1. 程式人生 > >CentOS 6 安裝 MySQL 8.0.+

CentOS 6 安裝 MySQL 8.0.+

1.先查詢是否安裝MySQL

大多數centos 6 自帶 MySQL5.1

命令:

rpm -qa|grep mysql

執行:

[[email protected] ~]# rpm -qa|grep mysql
mysql-libs-5.1.73-7.el6.i686

2.若有則解除安裝

rpm -e --nodeps mysql-libs

--nodeps 是消除依賴的意思

3.去官網複製yum下載連結用wget下載到伺服器

https://dev.mysql.com/downloads/repo/yum/


命令:

wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm

成功:

[[email protected] ~]# wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
--2018-12-10 06:40:42--  
...
Length: 25800 (25K) [application/x-redhat-package-manager]
Saving to: “mysql80-community-release-el6-1.noarch.rpm”

2018-12-10 06:40:42 (95.8 MB/s) - “mysql80-community-release-el6-1.noarch.rpm” saved [25800/25800]

若沒有wget

[[email protected] ~]# wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
-bash: wget: command not found

安裝wget

yum -y install wget

4.安裝

第一步:

rpm -ivh mysql80-community-release-el6-1.noarch.rpm

執行成功結果:

[[email protected] ~]# rpm -ivh mysql80-community-release-el6-1.noarch.rpm
warning: mysql80-community-release-el6-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
1:mysql80-community-relea########################################### [100%]
[
[email protected]
~]#

第二步:

yum install mysql-server

執行後會跳出2次選擇,輸入y回車繼續即可,如:

[[email protected] ~]# yum install mysql-server
Loaded plugins: fastestmirror
...
Install       5 Package(s)
Total download size: 452 M
Installed size: 1.7 G
Is this ok [y/N]: y

輸入y繼續安裝:

...
Total                                                                                                                              16 MB/s | 452 MB     00:28     
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering <[email protected]>
Package: mysql80-community-release-el6-1.noarch (installed)
From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y

最後出現如下指令,安裝成功:

Installed:
mysql-community-server.i686 0:8.0.13-1.el6                      
Dependency Installed:
mysql-community-client.i686 0:8.0.13-1.el6  mysql-community-common.i686 0:8.0.13-1.el6  mysql-community-libs.i686 0:8.0.13-1.el6  numactl.i686 0:2.0.9-2.el6 
Complete!

5.查詢是否安裝成功

[[email protected] ~]# mysqladmin -V
mysqladmin  Ver 8.0.13 for Linux on i686 (MySQL Community Server - GPL)

6.開啟MySqL

[[email protected] ~]# service mysqld start
Initializing MySQL database:  
                                                   [  OK  ]
Starting mysqld:                                           [  OK  ]

檢視MySQL啟動狀態:

[[email protected] ~]# service mysqld status
mysqld (pid  3852) is running...

7.檢視系統給root自動生成的密碼

cat /var/log/mysqld.log

執行結果(密碼在第二行最後):

[[email protected] ~]# cat /var/log/mysqld.log
2018-12-10T12:19:20.303739Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3620
2018-12-10T12:19:24.878215Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: >J9tXQXwK3y=
2018-12-10T12:19:29.237165Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has completed
2018-12-10T12:19:32.011310Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 3852
2018-12-10T12:19:33.144590Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-12-10T12:19:33.201007Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2018-12-10T12:19:33.272837Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

8.命令列登入和修改密碼

[[email protected] ~]# mysql -uroot -p
Enter password: 

輸入上一步驟檢視的密碼(輸入時不顯示任何字元):

[[email protected] ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. 
...
mysql> 

修改密碼:

mySql5.7之後,必須修改密碼後才能操作.
並且對密碼要求嚴格,至少8位,包含大小寫等,若想設定成123456,則要以下兩條命令:

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

設定密碼:

mysql> alter user user() identified by '123456';
Query OK, 0 rows affected (0.09 sec)

9.遠端登入(Navicat)

注意:需關閉防火牆或者開放3306埠

service iptables stop #暫時關閉
chkconfig iptables off #設定成開啟不自啟
==========
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT #開啟3306埠 
/etc/rc.d/init.d/iptables save #儲存配置
/etc/rc.d/init.d/iptables restart #重啟服務 

遠端登入會報如下錯誤:


首先檢視使用者表,發現登入主機是localhost,當然不能登入,把root使用者的localhost設定為%,這樣任意主機都可以連線。

mysql> use mysql;
Database changed
mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
    +------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql> update user set host = '%' where user ='root';

再重新整理一下:

flush privileges;

這時該問題已解決,若報如下錯誤,則是版本加密方式的改變

登入後請依次執行如下命令:

use mysql; 

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; #更改加密方式

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';#更新使用者密碼

FLUSH PRIVILEGES;#重新整理許可權

再次連線成功: