Linux 7 安裝Mysql 5.7
在Oracle Linux 7.1中安裝MySql 5.7 。mysql安裝位置:/mysqlsoft/mysql,資料庫檔案資料位置:/mysqldata/mysql。
1.首先下載安裝介質
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2. 在根目錄下建立資料夾mysqlsoft和資料庫資料檔案/mysqldata/mysql
[root@cs2 /]# mkdir -p /mysqlsoft [root@cs2 /]# mkdir -p /mysqldata/mysql [root@cs2 /]# ls -lrt /mysqldata/ total 0 drwxr-xr-x 2 root root 6 May 31 11:58 mysql
3.上傳介質mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz到/mysqlsoft目錄中並解壓
[root@cs2 /]# cd mysqlsoft [root@cs2 mysqlsoft]# ls -lrt total 628704 -rw-r--r-- 1 root root 643790848 Apr 20 2018 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz [root@cs2 mysqlsoft]# tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz [root@cs2 mysqlsoft]# ls -lrt total 628704 -rw-r--r-- 1 root root 643790848 Apr 20 2018 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz drwxr-xr-x 9 root root 120 May 31 12:11 mysql-5.7.22-linux-glibc2.12-x86_64
建議一般不要修改預設檔名,透過軟連線來完成
[root@cs2 mysqlsoft]# mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql [root@cs2 mysqlsoft]# ls -lrt total 628704 -rw-r--r-- 1 root root 643790848 Apr 20 2018 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz drwxr-xr-x 9 root root 120 May 31 13:28 mysql-5.7.22-linux-glibc2.12-x86_64 lrwxrwxrwx 1 root root 35 May 31 13:33 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64 [root@cs2 mysqlsoft]# cd mysql [root@cs2 mysql]# ls bin COPYING docs include lib man README share support-files
4. 建立mysql使用者與使用者組
[root@cs2 mysql]# groupadd mysql [root@cs2 mysql]# useradd -r -g mysql -s /bin/false mysql
因為使用者只用於所有權目的,而不是登入目的,useradd命令使用-r與-s /bin/false選項來建立一個使用者沒有登入伺服器主機的許可權。
5.修改/mysqlsoft/mysql與/mysqldata/mysql目錄許可權
[root@cs2 /]# chown -R mysql:mysql /mysqlsoft/mysql [root@cs2 /]# chown -R mysql:mysql /mysqldata/mysql [root@cs2 /]# chmod -R 775 /mysqlsoft/mysql [root@cs2 /]# chmod -R 775 /mysqldata/mysql
6. MySQL對於libaio庫有依賴性。臺果這個libaio庫沒有安裝那麼資料目錄初始化與後續的資料庫服務啟動將會失敗,安裝libaio庫執行以下操作:
查詢是否安裝了libaio庫
[root@cs2 local]# yum search libaio Loaded plugins: langpacks Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast =========================================================================================================== N/S matched: libaio ============================================================================================================ libaio.i686 : Linux-native asynchronous I/O access library libaio.x86_64 : Linux-native asynchronous I/O access library libaio-devel.i686 : Development files for Linux-native asynchronous I/O access libaio-devel.x86_64 : Development files for Linux-native asynchronous I/O access Name and summary matches only, use "search all" for everything.
如果沒有安裝,可以執行下面的命令來安裝
[root@cs2 local]# yum install libaio Loaded plugins: langpacks Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast file:///run/media/jy/OL-7.1%20Server.x86_64/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /run/media/jy/OL-7.1%20Server.x86_64/repodata/repomd.xml" Trying other mirror. Package libaio-0.3.109-12.el7.x86_64 already installed and latest version Nothing to do
7.配置mysql引數
只是設定幾個簡單的mysql執行引數
[root@cs2 ~]# vi /mysqlsoft/mysql/my.cnf [mysqld] basedir=/mysqlsoft/mysql datadir=/mysqldata/mysql bind-address=0.0.0.0 user=mysql port=3306 log-error=/mysqldata/mysql/mysql.err pid-file=/mysqldata/mysql/mysqld.pid socket = /mysqldata/mysql/mysql.sock character-set-server=utf8 default-storage-engine=INNODB explicit_defaults_for_timestamp = true "/mysqlsoft/mysql/my.cnf" [New] 67L, 1642C written
注意:log-error 一定要配置,因為如果mysql啟動錯誤,可以從日誌檔案中找到錯誤原因。其次bind—address配置0.0.0.0是為了監聽所有的連線。還有就是socket引數所指定的mysql.sock檔案的路徑最好設定為/tmp/mysql.sock,因為unix socket檔案的預設位置在/tmp目錄中。
8.初始化mysql
[root@cs2 /]# cd /mysqlsoft/mysql/bin [root@cs2 bin]# ./mysqld --user=mysql --defaults-file=/mysqlsoft/mysql/my.cnf --basedir=/mysqlsoft/mysql --datadir=/mysqldata/mysql --initialize [root@cs2 mysql]# cat mysql.err 2019-05-31T06:01:50.260643Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2019-05-31T06:01:50.260731Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 100 100 2019-05-31T06:01:53.795162Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-05-31T06:01:54.049268Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-05-31T06:01:54.102171Z 0 [ERROR] unknown variable 'defaults-file=/mysqlsoft/mysql/my.cnf' 2019-05-31T06:01:54.102193Z 0 [ERROR] Aborting
網上有人說是檔案許可權的問題,然後重新授權chmod 664 my.cnf 但並沒有解決,有人建議調整一下引數順序就好!!!最後調整了一下引數順序果然有效:
[root@cs2 bin]# ./mysqld --defaults-file=/mysqlsoft/mysql/my.cnf --initialize --basedir=/mysqlsoft/mysql --datadir=/mysqldata/mysql --user=mysql [root@cs2 mysql]# cat mysql.err 2019-05-31T06:05:06.362925Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2019-05-31T06:05:06.362994Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 100 100 2019-05-31T06:05:09.779913Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-05-31T06:05:10.026707Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-05-31T06:05:10.094462Z 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: 0be6983a-836a-11e9-a341-005056a092af. 2019-05-31T06:05:10.109209Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-05-31T06:05:10.110107Z 1 [Note] A temporary password is generated for root@localhost: ,;pm93qnL%-j 2019-05-31T06:05:14.966324Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966373Z 1 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966391Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966419Z 1 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966428Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966441Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966493Z 1 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-31T06:05:14.966508Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
其中[Note] A temporary password is generated for root@localhost: ,;pm93qnL%-j的root@localhost: 後面跟的是mysql資料庫登入的臨時密碼,各人安裝生成的臨時密碼不一樣。可以看到到日誌檔案沒有報錯,而且有了臨時密碼,表示初始化成功。
9. 如果想服務能夠部署自動支援安全連線,使用mysql_ssl_rsa_setup工具來建立預設SSL與RSA檔案
[root@cs2 bin]# ./mysql_ssl_rsa_setup --datadir=/mysqldata/mysql Generating a 2048 bit RSA private key ......................................................................+++ ..............................................................+++ writing new private key to 'ca-key.pem' ----- Generating a 2048 bit RSA private key .............+++ ..............+++ writing new private key to 'server-key.pem' ----- Generating a 2048 bit RSA private key .....................................+++ ................................................+++ writing new private key to 'client-key.pem' -----
9.啟動mysql服務
[root@cs2 /]# sh /mysqlsoft/mysql/support-files/mysql.server start /mysqlsoft/mysql/support-files/mysql.server: line 239: my_print_defaults: command not found /mysqlsoft/mysql/support-files/mysql.server: line 259: cd: /usr/local/mysql: No such file or directory Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
啟動mysql服務命令會報錯,因為沒有修改mysql的配置檔案
修改Mysql配置檔案,修改前為以下內容
if test -z "$basedir" then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin if test -z "$datadir" then datadir=/usr/local/mysql/data fi sbindir=/usr/local/mysql/bin libexecdir=/usr/local/mysql/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="$basedir/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi
修改後的內容如下
[root@cs2 ~]# vi /mysqlsoft/mysql/support-files/mysql.server if test -z "$basedir" then basedir=/mysqlsoft/mysql bindir=/mysqlsoft/mysql/bin if test -z "$datadir" then datadir=/mysqldata/mysql fi sbindir=/mysqlsoft/mysql/bin libexecdir=/mysqlsoft/mysql/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="$basedir/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi [root@cs2 ~]# cp /mysqlsoft/mysql/support-files/mysql.server /etc/init.d/mysqld [root@cs2 ~]# chmod 755 /etc/init.d/mysqld
10.啟動mysql
[root@cs2 ~]# service mysqld start Starting MySQL.. SUCCESS!
11.配置環境變數
[root@cs2 ~]# vi /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. export MYSQL_HOME=/mysqlsoft/mysql/ export PATH=$PATH:$MYSQL_HOME/bin
11.登入Mysql
初始化成功後,檢視初始化密碼
[root@cs2 ~]# cat /mysqldata/mysql/mysql.err | grep password 2019-05-31T06:05:10.110107Z 1 [Note] A temporary password is generated for root@localhost: ,;pm93qnL%-j
並輸入剛剛複製的密碼,但是 卻提示不能透過mysql.sock檔案實現連線
[root@cs2 bin]# ./mysqladmin -u root -p password Enter password: mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/mysqlsoft/mysql/mysql.sock' (2)' Check that mysqld is running and that the socket: '/mysqlsoft/mysql/mysql.sock' exists!
這裡就奇怪了,因為在my.cnf檔案中設定的socket檔案路徑為/mysqldata/mysql/mysql.sock,但mysql所使用的檔案不是啟動服務所生成的。
[root@cs2 ~]# cat /mysqlsoft/mysql/my.cnf [mysqld] basedir=/mysqlsoft/mysql datadir=/mysqldata/mysql bind-address=0.0.0.0 user=mysql port=3306 log-error=/mysqldata/mysql/mysql.err pid-file=/mysqldata/mysql/mysqld.pid socket = /mysqldata/mysql/mysql.sock character-set-server=utf8 default-storage-engine=INNODB explicit_defaults_for_timestamp = true [root@cs2 mysql]# ls -lrt total 286896 -rw-r----- 1 mysql mysql 134217728 May 31 14:05 ib_logfile1 -rw-r----- 1 mysql mysql 56 May 31 14:05 auto.cnf drwxr-x--- 2 mysql mysql 8192 May 31 14:05 performance_schema drwxr-x--- 2 mysql mysql 4096 May 31 14:05 mysql drwxr-x--- 2 mysql mysql 8192 May 31 14:05 sys -rw------- 1 mysql mysql 1679 May 31 14:25 ca-key.pem -rw-r--r-- 1 mysql mysql 1107 May 31 14:25 ca.pem -rw------- 1 mysql mysql 1679 May 31 14:25 server-key.pem -rw-r--r-- 1 mysql mysql 1107 May 31 14:25 server-cert.pem -rw------- 1 mysql mysql 1679 May 31 14:25 client-key.pem -rw-r--r-- 1 mysql mysql 1107 May 31 14:25 client-cert.pem -rw------- 1 mysql mysql 1679 May 31 14:25 private_key.pem -rw-r--r-- 1 mysql mysql 451 May 31 14:25 public_key.pem -rw-r----- 1 mysql mysql 291 May 31 18:05 ib_buffer_pool -rw------- 1 mysql mysql 6 May 31 18:08 mysql.sock.lock srwxrwxrwx 1 mysql mysql 0 May 31 18:08 mysql.sock -rw-r----- 1 mysql mysql 6 May 31 18:08 mysqld.pid -rw-r----- 1 mysql mysql 101396 May 31 18:08 mysql.err -rw-r----- 1 mysql mysql 12582912 May 31 18:08 ibtmp1 -rw-r----- 1 mysql mysql 12582912 May 31 18:08 ibdata1 -rw-r----- 1 mysql mysql 134217728 May 31 18:08 ib_logfile0
可以看到在/var/lib/mysql目錄中的mysql.sock是指向/mysqlsoft/mysql/mysql.sock檔案的。
[mysql@cs2 ~]$ ls -lrt /var/lib/mysql 總用量 110604 -rw-rw----. 1 27 27 50331648 10月 11 2017 ib_logfile1 drwx------. 2 27 27 4096 10月 11 2017 performance_schema drwx------. 2 27 27 4096 10月 11 2017 mysql -rw-rw----. 1 27 27 56 10月 11 2017 auto.cnf -rw-rw----. 1 27 27 50331648 5月 30 18:32 ib_logfile0 -rw-rw----. 1 27 27 12582912 5月 30 18:32 ibdata1 lrwxrwxrwx 1 root root 27 5月 31 15:44 mysql.sock -> /mysqlsoft/mysql/mysql.sock
如果使用-S選項來指定生成的mysql.sock檔案進行登入是可以成功登入的
[mysql@cs2 mysql]$ mysql -S /mysqldata/mysql/mysql.sock -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> quit
修改socket檔案路徑為/mysqlsoft/mysql/mysql.sock
[root@cs2 ~]# cat /mysqlsoft/mysql/my.cnf [mysqld] basedir=/mysqlsoft/mysql datadir=/mysqldata/mysql bind-address=0.0.0.0 user=mysql port=3306 log-error=/mysqldata/mysql/mysql.err pid-file=/mysqldata/mysql/mysqld.pid socket = /mysqlsoft/mysql/mysql.sock character-set-server=utf8 default-storage-engine=INNODB explicit_defaults_for_timestamp = true
再重啟mysql服務
[root@cs2 ~]# service mysqld stop Shutting down MySQL.. SUCCESS! [root@cs2 ~]# service mysqld start Starting MySQL.. SUCCESS! [mysql@cs2 ~]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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>
這就可以登入了。
12.重置root使用者密碼
[mysql@cs2 ~]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.22 Copyright (c) 2000, 2018, 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> set password=password("123456"); Query OK, 0 rows affected, 1 warning (0.00 sec)
13.設定允許遠端登入mysql
如果要遠端訪問資料庫,只需要把擁有全部許可權的root賬號對應的記錄的Host欄位改為%就可以了
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to root@'%'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
測試遠端登入
-bash-4.2$ mysql -h 10.11.13.19 -P 3306 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT DISTINCT CONCAT('User: [', user, '''@''', host, '];') AS USER_HOST FROM user; +------------------------------------+ | USER_HOST | +------------------------------------+ | User: [root'@'%]; | | User: [mysql.session'@'localhost]; | | User: [mysql.sys'@'localhost]; | +------------------------------------+ 3 rows in set (0.05 sec)
到此所有的安裝步驟就完成,安裝還是相當簡單的。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2646540/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS 7 安裝 MySQL 5.7CentOSMySql
- CentOS 7 - 安裝MySQL 5.7CentOSMySql
- Linux下安裝MySQL 5.7LinuxMySql
- mysql5.7安裝_centos7MySqlCentOS
- CentOS7 安裝mysql5.7CentOSMySql
- linux離線安裝mysql5.7LinuxMySql
- CentOS7下yum安裝MySQL 5.7CentOSMySql
- CentOS7 yum安裝MySQL5.7CentOSMySql
- Linux使用原始碼來安裝MySQL 5.7Linux原始碼MySql
- centos7安裝mysql5.7 使用yumCentOSMySql
- CentOS7利用docker安裝MySQL5.7CentOSDockerMySql
- 在centos7上安裝mysql5.7CentOSMySql
- Centos7下安裝配置MySQL5.7CentOSMySql
- Linux下安裝Nginx+PHP7.1+MySQL5.7LinuxNginxPHPMySql
- CentOS 7 利用yum安裝lnmp的教程(Linux+Nginx+PHP7.1+Mysql5.7)CentOSLNMPLinuxNginxPHPMySql
- Docker 安裝 Mysql 5.7DockerMySql
- CentOS7 透過YUM安裝MySQL5.7CentOSMySql
- windows 7 vs 2013編譯與安裝MySQL 5.7Windows編譯MySql
- 基於Linux的MySQL5.7RPM包安裝LinuxMySql
- CentOS7下MySQL5.7安裝與配置(YUM)CentOSMySql
- centos安裝mysql5.7CentOSMySql
- mysql5.7 安裝教程MySql
- 基於centos7進行yum安裝lnmp linux+nginx+php7.1+mysql5.7CentOSLNMPLinuxNginxPHPMySql
- Centos 7 升級通過 yum 安裝的 MySQL 5.7 到 MySQL 8.0CentOSMySql
- CentOS 7 系統安裝與遠端連線 MySQL 5.7CentOSMySql
- 在CentOS7上安裝MySQL5.7-YUM源方式CentOSMySql
- CentOS 7 下使用yum安裝MySQL5.7方法CentOSMySql
- Ubuntu 16.04 上安裝 MySQL 5.7UbuntuMySql
- Windows安裝MySQL5.7教程WindowsMySql
- Ubuntu 18.04 安裝配置 MySQL 5.7UbuntuMySql
- MySQL:mysql5.7解壓版安裝與解除安裝MySql
- 基於Linux的MySQL5.7原始碼編譯安裝LinuxMySql原始碼編譯
- Mysql 5.7 免安裝版windows安裝完整教程MySqlWindows
- Centos7系統如何安裝MySQL5.7資料庫?CentOSMySql資料庫
- CentOS7 64位下MySQL5.7安裝與配置(YUM)CentOSMySql
- mysql-5.7.xx在lcentos7下的安裝以及mysql在windows以及linux上的效能差異MySqlCentOSWindowsLinux
- macOS Mojave 降級安裝 MySQL 5.7MacMySql
- mysql5.7tar包的安裝MySql