mysql安裝流程

[root@n5 ~]# rpm -q mariadb-server mariadb    #如果之前安裝過mariadb,需要卸載

[root@n5 ~]# ls    #把安裝包上傳到root目錄下
anaconda-ks.cfg  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

[root@n5 ~]# useradd -r mysql    #創建一個系統用戶mysql

[root@n5 ~]# id mysql
uid=997(mysql) gid=995(mysql) groups=995(mysql)

[root@n5 ~]# tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local    #展開安裝包

[root@n5 ~]# cd /usr/local/
[root@n5 local]# ln -sn mysql-5.7.18-linux-glibc2.5-x86_64/ mysql    #制作鏈接文件
lrwxrwxrwx  1 root root  35 Apr 12 23:20 mysql -> mysql-5.7.18-linux-glibc2.5-x86_64/
[root@n5 local]# cd mysql
[root@n5 mysql]# chown -R root.mysql ./\*    #修改mysql所有文件屬組為mysql
[root@n5 mysql]# ll
total 36
drwxr-xr-x  2 root mysql  4096 Apr 12 23:16 bin
-rw-r--r--  1 root mysql 17987 Mar 18  2017 COPYING
drwxr-xr-x  2 root mysql    55 Apr 12 23:16 docs
drwxr-xr-x  3 root mysql  4096 Apr 12 23:16 include
drwxr-xr-x  5 root mysql   229 Apr 12 23:16 lib
drwxr-xr-x  4 root mysql    30 Apr 12 23:16 man
-rw-r--r--  1 root mysql  2478 Mar 18  2017 README
drwxr-xr-x 28 root mysql  4096 Apr 12 23:16 share
drwxr-xr-x  2 root mysql    90 Apr 12 23:16 support-files
[root@n5 mysql]# mkdir -pv /data/mysql    #創建mysql數據目錄
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysql’
[root@n5 mysql]# chown -R mysql.mysql /data/mysql/    #mysql進程要進行寫操作,修改權限
[root@n5 mysql]# ll /data
total 0
drwxr-xr-x 2 mysql mysql 6 Apr 12 23:28 mysql
[root@n5 mysql]# vim /etc/profile.d/mysql.sh    #編寫修改環境變量腳本
export PATH=/usr/local/mysql/bin:$PATH
[root@n5 mysql]# . /etc/profile.d/mysql.sh    #讀取環境變量

[root@n5 mysql]# mkdir etc
[root@n5 mysql]# mkdir logs
[root@n5 mysql]# chown -R mysql.mysql logs/    #更改日志目錄權限
[root@n5 mysql]# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
2018-04-13T05:28:25.149583Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-13T05:28:25.948412Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-13T05:28:26.058553Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-13T05:28:26.121981Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7da0526b-3edb-11e8-a71c-000c2977a305.
2018-04-13T05:28:26.124459Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-04-13T05:28:26.127938Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@n5 mysql]# cp /etc/my.cnf etc/
[root@n5 mysql]# vim etc/my.cnf    #修改mysql配置文件
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/var/run/mysql/mysql.pid
!includedir /usr/local/mysql/etc/my.cnf.d

[root@n5 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@n5 mysql]# ll /etc/init.d/mysqld    #確保有執行權限
-rwxr-xr-x 1 root root 10576 Apr 13 01:39 /etc/init.d/mysqld
[root@n5 mysql]# chkconfig --add mysqld
[root@n5 mysql]# mkdir etc/my.cnf.d
[root@n5 mysql]# touch logs/error.log    #新建錯誤日志文件
[root@n5 mysql]# chown -R mysql.mysql logs/error.log    #修改錯誤日志文件屬主屬組
[root@n5 mysql]# service mysql start    #開啟mysql服務
Redirecting to /bin/systemctl start mysql.service
[root@n5 mysql]# mysql    #運行mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容