CentOS7(Linux)下安裝MySQL服務

下載

先去網站MySQL下載頁面去挑下載包,選擇了RedHat Enterprise Linux 7下面的TAR,[TAR包下載地址]([root@mini-like data]# wget )
我是直接下載到服務器了:

[root@mini-like data]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.27-1.el7.x86_64.rpm
[root@mini-like data]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.27-el7-x86_64.tar

解壓後用rpm -ivh命令很快就安裝成功了
下面開始登錄,初始化創建密碼:

[root@mini-like ~]# mysql -Uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

啊,有錯誤了,用系統密碼試試看?什麼?也失敗了。查資料吧,據說從5.7開始密碼採用隨機密碼,在~/.mysqlXXXX文件裏,我找了半天只找到一個history文件,不是。查日誌吧,果然,纔看了10來行就找到了:

[root@mini-like ~]# cat /var/log/mysqld.log
2020-03-17T14:23:24.145021Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-17T14:23:26.451208Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-17T14:23:26.657299Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-17T14:23:26.799614Z 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: ddef0450-685a-11ea-b3e8-00163e127c61.
2020-03-17T14:23:26.803394Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-17T14:23:26.806934Z 1 [Note] A temporary password is generated for root@localhost: 4mG5/dz7sBV9
[root@mini-like ~]# mysql -Uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

密碼是找到了,可是還是不能登錄,怎麼辦,先免密登錄?

[root@mini-like ~]# vim /etc/my.cnf
# 找到[mysqld],在後面補上一行:
skip-grant-tables
# 保存退出,重新啓動mysqld
現在可用
mysql> update  user set password_expired='N' where User='root';

現在把過期的密碼改爲不過期了,4mG5/dz7sBV9終於可以當做密碼登錄了。
找回skip-grant-tables,屏蔽,重新啓動mysql。然後用密碼登錄進去後修改密碼:

mysql> update user set Host = '%',password=password('123') where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

隨後,我們刷新權限

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

下面就可以用工具連進去創建賬戶了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章