CentOS 7 系統安裝與遠端連線 MySQL 5.7

java06051515發表於2018-11-14

CentOS 7 版本將MySQL資料庫軟體從預設的程式列表中移除,那麼CentOS 7版本如何安裝MySQL呢,本文將指導大傢俱體的方法。

以滴滴雲DC2雲主機上的操作為例,首先切換賬戶許可權到root許可權,登入CentOS 7 系統的雲主機後輸入:

[dc2-user@didiyun dc2-user]# sudo su

切換成root許可權,然後執行下面的安裝方法:

官網安裝mysql-server方法:

[root@didiyun dc2-user]# yum install -y wget

[root@didiyun dc2-user]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

[root@didiyun dc2-user]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm

[root@didiyun dc2-user]# yum install mysql-community-server -y

啟動MySQL

[root@didiyun dc2-user]# systemctl start mysqld

驗證是否啟動

[root@didiyun dc2-user]# systemctl status mysqld

MySQL安裝完成之後,在/var/log/mysqld.log檔案中給root生成了一個預設密碼。透過下面的方式找到root預設密碼,然後登入MySQL進行修改:

[root@didiyun dc2-user]# grep 'temporary password' /var/log/mysqld.log

2018-05-23T09:24:03.800263Z 1 [Note] A temporary password is generated for root@localhost: p?iT>b?iv7st

可以看到初始密碼為 p?iT>b?iv7st,登入資料庫:

[root@didiyun dc2-user]# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.22Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

重新設定root密碼

mysql> set password for 'root'@'localhost'=password('Mypass12@');

為資料庫設定遠端連線

首先在防火牆規則中開啟3306埠

設定MySQL

mysql> grant all privileges on *.* to root@'%'identified by '123456';

如果是非root使用者(mysql的root使用者)遠端登入,則要先建立使用者

mysql>create user 'username'@'%' identified by 'password';

然後再進行連線

[root@didiyun dc2-user]#mysql -h <IP地址> -uusername -p

Enter password: ******

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 11

Server version: 5.6.39 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>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31559758/viewspace-2219922/,如需轉載,請註明出處,否則將追究法律責任。

相關文章