天天看點

CentOS 8安裝Mysql8并設定開機自啟動

0. 看起來mysql又提供yum安裝了。

yum install mysql-server

後面的沒時間可以不看了。

先要安裝wget

yum -y install wget

1. 下載下傳rpm安裝檔案

wget http://repo.mysql.com/mysql-community-release-el7.rpm

2. 執行rpm安裝

rpm -ivh mysql-community-release-el7.rpm

依賴解析完成後,出現下列選項:

1 Dependencies Resolved

2

3 ================================================================================================================================================================

4 Package Arch Version Repository Size

5 ================================================================================================================================================================

6 Installing:

7 mysql-community-libs x86_64 5.6.32-2.el7 mysql56-community 2.0 M

8 replacing mariadb-libs.x86_64 1:5.5.47-1.el7_2

9 mysql-community-server x86_64 5.6.32-2.el7 mysql56-community 59 M

10 Installing for dependencies:

11 mysql-community-client x86_64 5.6.32-2.el7 mysql56-community 19 M

12 mysql-community-common x86_64 5.6.32-2.el7 mysql56-community 256 k

13 perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k

14 perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k

15 perl-DBI x86_64 1.627-4.el7 base 802 k

16 perl-IO-Compress noarch 2.061-2.el7 base 260 k

17 perl-Net-Daemon noarch 0.48-5.el7 base 51 k

18 perl-PlRPC noarch 0.2020-14.el7 base 36 k

19

20 Transaction Summary

21 ================================================================================================================================================================

22 Install 2 Packages (+8 Dependent packages)

23

24 Total download size: 82 M

25 Is this ok [y/d/N]:

3. 可以看出,server和client都被選擇安裝。選擇y,自動下載下傳安裝。

4. 安裝完成後,啟動Mysql。

systemctl start  mysqld.service

啟動方式

1、使用 service 啟動:service mysqld start

2、使用 mysqld 腳本啟動:/etc/inint.d/mysqld start

二、停止

1、使用 service 啟動:service mysqld stop

2、使用 mysqld 腳本啟動:/etc/inint.d/mysqld stop

三、重新開機

1、使用 service 啟動:service mysqld restart

2、使用 mysqld 腳本啟動:/etc/inint.d/mysqld restart

登入mysql:mysql -u root -p

5. 設定root密碼。

​ALTER USER 'root'@'localhost' IDENTIFIED BY '密碼';​

​​(注意要切換到mysql資料庫,使用​

​use mysql​

​)

/*update user set password=password("123456") where user='root';*/

6. 開機自啟動。

1 vim /etc/rc.local

2 添加service mysqld start

啟動Mysql服務

      systemctl start mysqld

設定開機啟動

       systemctl enable mysqld

       systemctl daemon-reload

7.重要更新:

新的rpm安裝檔案沒有自動yum安裝的腳本了,需要手動執行yum安裝。

即步驟2之後執行yum install mysql-server即可。

8.關于自啟動

步驟6隻适用于mysqld沒有自啟動的條件下。

如果預設mysql是自啟動的,可能和rc.local中的自啟動出現亂序之類的問題。

更穩妥的一個解決辦法見:

CentOS 7 程式自啟動的問題

打開遠端通路:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '密碼' WITH GRANT OPTION;

1:linux登入mysql

[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.13 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>      

2:檢視user表,修改連接配接級别

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 host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)      
update user set host='%' where user='root';      

3:可能你覺得到這一步就完事了,但是使用navicat連接配接測試時,會提示無法解析主機名相關的錯誤,這是mysql8的一些安全政策的問題,具體請左轉google,解決辦法如下

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpassword';      

繼續閱讀