CentOS7 安裝MYSQL5.7 [詳細過程] YUM 安裝 1.從mysql官網獲取 yum 倉庫 [root@stone tmp]# wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm' 2. ...
CentOS7 安裝MYSQL5.7 [詳細過程]
YUM 安裝
1.從mysql官網獲取 yum 倉庫
[root@stone tmp]# wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
2.安裝yum repo
[root@stone tmp]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
警告:mysql57-community-release-el7-11.noarch.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:mysql57-community-release-el7-11 ################################# [100%]
3.安裝mysql
[root@stone tmp]# yum install -y mysql-community-server
4.如果安裝過程中出現如下錯誤
源 "MySQL 5.7 Community Server" 的 GPG 密鑰已安裝,但是不適用於此軟體包。請檢查源的公鑰 URL 是否配置正確。
使用如下命令
[root@stone rpm-gpg]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
5.啟動mysql
[root@stone rpm-gpg]# systemctl start mysqld.service
6.查看運行狀態
[root@stone rpm-gpg]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2022-05-01 00:00:35 CST; 30s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2067 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 2018 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2070 (mysqld)
CGroup: /system.slice/mysqld.service
└─2070 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 01 00:00:32 stone systemd[1]: Starting MySQL Server...
5月 01 00:00:35 stone systemd[1]: Started MySQL Server.
7.登錄資料庫
第一次啟動的密碼在日誌中查找
[root@stone rpm-gpg]# cat /var/log/mysqld.log | grep password
2022-04-30T16:00:33.315107Z 1 [Note] A temporary password is generated for root@localhost: ZpiMyUag.4wl
[root@stone rpm-gpg]#
8.登錄後修改密碼,如果要是設置複雜密碼可以直接使用如下命令 直接設置
mysql> SET PASSWORD = PASSWORD('your new password');
mysql> flush privileges;
- 如果要設置簡單密碼 則需要先使用如下命令 設置密碼策略
mysql> set global validate_password_policy=0;#設置密碼檢查策略為0
mysql> set global validate_password_length=1;#設置密碼的長度為1
10.授權用戶登錄許可權
mysql> grant all privileges on *.* to root@"%" identified by "new passwd";
mysql> flush privileges;
11.如果忘記密碼
1. 暫停服務
systemctl stop mysql.service
2. 修改/etc/my.cnf
添加 skip-grant-tables 配置項目
3. 重啟mysql服務
4. mysql -uroot -p 進入資料庫
5. update user set password = password ( 'new-password' ) where user = 'root';
6. flush privileges;