CentOS7安裝MySQL以及密碼修改

2021-10-22 08:54:47 字數 4300 閱讀 4385

wget -i -c
yum -y install mysql57-community-release-el7-10.noarch.rpm
之後就開始安裝mysql伺服器。

yum -y install mysql-community-server
這步可能會花些時間,安裝完成後就會覆蓋掉之前的mariadb。

至此mysql就安裝完成了,然後是對mysql的一些設定。

[root@localhost ~]# systemctl start  mysqld.service
檢視mysql執行狀態,執行狀態如圖:

此時mysql已經開始正常執行,不過要想進入mysql還得先找出此時root使用者的密碼,通過如下命令可以在日誌檔案中找出密碼:

grep "password" /var/log/mysqld.log
image

如下命令進入資料庫:

mysql -u root -p
輸入初始密碼,此時不能做任何事情,因為mysql預設必須修改密碼之後才能運算元據庫:

mysql> alter user 'root'@'localhost' identified by 'new password';
這裡有個問題,新密碼設定的時候如果設定的過於簡單會報錯:

image

原因是因為mysql有密碼設定的規範,具體是與validate_password_policy的值有關:

mysql完整的初始密碼規則可以通過如下命令檢視:

密碼的長度是由validate_password_length決定的,而validate_password_length的計算公式是:

validate_password_length = validate_password_number_count +validate_password_special_char_count + (2* validate_password_mixed_case_count)
我的是已經修改過的,初始情況下第乙個的值是on,validate_password_length是8。可以通過如下命令修改:

mysql> set global validate_password_policy=0;

mysql> set global validate_password_length=1;

設定之後就是我上面查出來的那幾個值了,此時密碼就可以設定的很簡單,例如1234之類的。到此資料庫的密碼設定就完成了。

但此時還有乙個問題,就是因為安裝了yum repository,以後每次yum操作都會自動更新,需要把這個解除安裝掉:

[root@localhost ~]#yum -y remove mysql57-community-release-el7-10.noarch
此時才算真的完成了。

mysql -u root -p

mysql>use mysql;

mysql>select 'host' from user where user='root';

mysql>update user set host = '%' where user ='root';

mysql>flush privileges;

mysql>select 'host' from user where user='root';

第一句是以許可權使用者root登入

第二句:選擇mysql庫

第三句:檢視mysql庫中的user表的host值(即可進行連線訪問的主機/ip名稱)

第六句:再重新檢視user表時,有修改。。

重起mysql服務即可完成。

開啟mysql配置檔案vi /etc/mysql/mysql.conf.d/mysqld.cnf

將bind-address = 127.0.0.1登出​

bind-address = 0.0.0.0 # 表示允許任何主機登陸mysql

port=3306 # 表示mysql執行埠為3306

2、支援root使用者允許遠端連線mysql資料庫

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

flush privileges;

/etc/init.d/mysql start

mysql5.6

grant all privileges on *.* to root@'%' identified by "mysql_pwd" with grant option;

grant all privileges on *.* to root@'localhost' identified by "mysql_pwd" with grant option;

grant all privileges on *.* to root@'127.0.0.1' identified by "mysql_pwd" with grant option;

drop database if exists test;

use mysql;

delete from user where not (user='root');

delete from db where user='';

update user set password=password('mysql_pwd') where user='root' and host='127.0.0.1' or host='%' or host='localhost';

delete from user where password='';

flush privileges;

select user,password,host from mysql.user;

exit;

mysql5.7:

grant all privileges on *.* to root@'%' identified by "mysql_pwd" with grant option;

grant all privileges on *.* to root@'localhost' identified by "mysql_pwd" with grant option;

grant all privileges on *.* to root@'127.0.0.1' identified by "mysql_pwd" with grant option;

drop database if exists test;

use mysql;

delete from user where not (user='root');

delete from db where user='';

delete from user where authentication_string='';

update mysql.user set authentication_string=password('mysql_pwd') where user='root' and host='127.0.0.1' or host='%' or host='localhost';

flush privileges;

select user,authentication_string,host from mysql.user;

exit;

centos7原始碼安裝mysql5 7以及解除安裝教程

2.解壓到指定目錄 tar zxvf mysql 5.7.26 linux glibc2.12 x86 64.tar.gz c usr local 3.重新命名 mv usr local mysql 5.7.26 linux glibc2.12 x86 64 usr local mysql 4.新建...

centos7以yum方式安裝docker

yum包更新到最新 sudo yum update 設定yum源為阿里雲 sudo yum config manager add repo 安裝docker sudo yum install docker ce 檢視docker版本 docker v 設定ustc的映象 ustc docker mi...

centos 7 安裝MySQL 筆記

1.安裝 wget rpm ivh mysql community release el7 5.noarch.rpm yum install mysql community server 成功安裝之後重啟mysql服務 service mysqld restart 初次安裝mysql是root賬戶是...