Linux之yum安裝MySQL

1. 下載并安裝MySQL官方的 Yum Repository

(1)使用下面的命令就直接下載了安裝用的Yum Repository,大概25KB的樣子,然后就可以直接yum安裝了。

[root@yzl yzl /]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@yzl yzl /]# yum -y install mysql57-community-release-el7-10.noarch.rpm

安裝完成后會(huì)有如下提示:

Running transaction
  正在安裝    : mysql57-community-release-el7-10.noarch                            1/1 
  驗(yàn)證中      : mysql57-community-release-el7-10.noarch                            1/1 
已安裝:
  mysql57-community-release.noarch 0:el7-10                                            

完畢!

(2)下面就是使用yum安裝MySQL了,這步可能會(huì)花些時(shí)間,安裝完成后就會(huì)覆蓋掉之前的mariadb。

[root@yzl yzl /]# yum -y install mysql-community-server

安裝成功后會(huì)有如下提示:

已安裝:
  mysql-community-libs.x86_64 0:5.7.23-1.el7                                           
  mysql-community-libs-compat.x86_64 0:5.7.23-1.el7                                    
  mysql-community-server.x86_64 0:5.7.23-1.el7                                         

作為依賴被安裝:
  mysql-community-client.x86_64 0:5.7.23-1.el7                                         
  mysql-community-common.x86_64 0:5.7.23-1.el7                                         

替代:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                   

完畢!

2. MySQL數(shù)據(jù)庫(kù)設(shè)置

(1)首先啟動(dòng)MySQL

[root@yzl yzl  /]# systemctl start  mysqld.service

(2)查看MySQL運(yùn)行狀態(tài),運(yùn)行狀態(tài)如圖:

[root@yzl yzl  /]# systemctl status mysqld.service

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2018-08-31 11:06:13 CST; 1min 19s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 6765 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 6678 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 6768 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─6768 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid...

8月 31 11:05:51 yzl systemd[1]: Starting MySQL Server...
8月 31 11:06:13 yzl systemd[1]: Started MySQL Server.

(3)此時(shí)MySQL已經(jīng)開始正常運(yùn)行,不過要想進(jìn)入MySQL還得先找出此時(shí)root用戶的密碼,通過如下命令可以在日志文件中找出密碼:

[root@yzl yzl  /]# grep "password" /var/log/mysqld.log

2018-08-31T03:06:07.947523Z 1 [Note] A temporary password is generated for root@localhost: 1!0dT>9qF2rR

初始密碼為:1!0dT>9qF2rR
(4)如下命令進(jìn)入數(shù)據(jù)庫(kù):

[root@yzl yzl]# 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> 

此時(shí)不能做任何事情,因?yàn)镸ySQL默認(rèn)必須修改密碼之后才能操作數(shù)據(jù)庫(kù):

(5)修改密碼

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
    
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

我們嘗試將密碼修改為root,發(fā)現(xiàn)報(bào)錯(cuò),原因密碼過于簡(jiǎn)單。剛安裝的mysql的密碼默認(rèn)強(qiáng)度是最高的,如果想要設(shè)置簡(jiǎn)單的密碼就要修改validate_password_policy的值,

validate_password_policy有以下取值:

mysql> set global validate_password_policy=0; #設(shè)置安全級(jí)別
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=4;#默認(rèn)密碼長(zhǎng)度為8,可以設(shè)置為其它值,最小4位
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.01 sec)

3.可視化工具的登錄授權(quán):(如果授權(quán)不成功,請(qǐng)查看防火墻)

操作完成上面的,現(xiàn)在還不能用可視化的客戶端進(jìn)行連接,需要我們進(jìn)行授權(quán):

mysql> grant all on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容