環境:
- 操作系統: CentOS7.0
- MySQL版本:mysql-5.7.23-1.el7.x86_64
准備:
下載rpm包: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
安裝步驟
<1>檢查卸載mariadb-lib
#檢查 [root@imok ~]# rpm -qa|grep mariadb mariadb-libs-5.5.35-3.el7.x86_64 #卸載 [root@imok ~]# rpm -e mariadb-libs-5.5.35-3.el7.x86_64 --nodeps
<2>上傳mysql安裝包並解壓
[root@imok tar.gz]# tar -xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql/
<3>安裝相關依賴
安裝mysql-server需要以下安裝包
- mysql-community-common-5.7.23-1.el7.x86_64.rpm
- mysql-community-libs-5.7.23-1.el7.x86_64.rpm
- mysql-community-client-5.7.23-1.el7.x86_64.rpm
- mysql-community-server-5.7.23-1.el7.x86_64.rpm
安裝以上四個需要安裝 libaio依賴 和 net-tools
安裝libbaio
[root@imok mysql]# yum -y install libaio
安裝net-tools
[root@imok mysql]# yum install net-tools
未安裝net-tools報錯提示:
warning: mysql-community-common-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
net-tools is needed by mysql-community-server-5.7.23-1.el7.x86_64
<4>安裝mysql-server
[root@imok mysql]# rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm mysql-community-libs-5.7.23-1.el7.x86_64.rpm mysql-community-client-5.7.23-1.el7.x86_64.rpm mysql-community-server-5.7.23-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.23-1.e################################# [ 25%]
2:mysql-community-libs-5.7.23-1.el7################################# [ 50%]
3:mysql-community-client-5.7.23-1.e################################# [ 75%]
4:mysql-community-server-5.7.23-1.e################################# [100%]
<5>數據庫初始化
[root@imok mysql]# mysqld --initialize --user=mysql
為了保證數據庫目錄為與文件的所有者為 mysql 登陸用戶,如果你是以 root 身份運行 mysql 服務,需要執行下面的命令初始化
mysqld --initialize --user=mysql
如果是以 mysql 身份運行,則可以去掉 --user
選項。
另外 --initialize
選項默認以“安全”模式來初始化,則會為 root 用戶生成一個密碼並將該密碼標記為過期,登陸后你需要設置一個新的密碼,而使用 --initialize-insecure
命令則不使用安全模式,則不會為 root 用戶生成一個密碼。
使用的 --initialize
初始化的,會生成一個 root 賬戶密碼,密碼在log文件里,紅色區域的就是自動生成的密碼
[root@imok mysql]# cat /var/log/mysqld.log 2018-08-02T11:44:44.783409Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-08-02T11:44:45.120708Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-08-02T11:44:45.170790Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-08-02T11:44:45.241814Z 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: 73aed9c6-9649-11e8-ae68-080027cf8d60. 2018-08-02T11:44:45.243701Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-08-02T11:44:45.244381Z 1 [Note] A temporary password is generated for root@localhost: I,mwy,zgD5U1
<6>啟動mysql服務
[root@imok mysql]# systemctl start mysqld.service
<7>登錄測試
[root@imok mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23 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> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示需要修改密碼。
<8>修改密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; Query OK, 0 rows affected (0.00 sec)
再次檢查
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '!QAZ2wsx' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.01 sec)
說明安裝成功!
遠程訪問失敗!!
解決方案:
(1)查看mysql遠程訪問策略是否關閉了,關閉則需要開啟3306(默認)端口訪問。參考 https://blog.csdn.net/qq_29944285/article/details/79369060
(2)如果開啟了訪問策略還是不能訪問,則需要確認遠程訪問用戶是否有權限。具體參考:https://www.cnblogs.com/beanmoon/p/3173924.html
參考:
https://blog.csdn.net/qq_29944285/article/details/79369060
https://www.cnblogs.com/beanmoon/p/3173924.html