CentOS 7下yum成功安裝 MySQL 5.7
- 第一部分:CentOS 7安裝MySQL 5.7
1.下載YUM庫
shell > wget dev.mysql.com/get/mysql57…
2.安裝YUM庫
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
3.安裝資料庫
yum install -y mysql-community-server
4.啟動MySQL服務
systemctl start mysqld.service
systemctl restart mysqld.service
5.預設空密碼
shell > mysql -uroot -p
6.重置root密碼後重啟mysql服務
shell > update mysql.user set authentication_string=password("FengZe123") where user="root" and Host="localhost";
shell > flush privileges;
shell > quit;
systemctl restart mysqld;
如果手賤或者不知道啥原因出現如下問題:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
請修改my.cnf,新增skip-grant-tables和skip-networking:
shell > vi /etc/my.cnf
[mysqld]
skip-grant-tables
skip-networking
重啟mysql,然後重複以上修改密碼步驟即可,記得修改完後,去掉my.cnf新增的兩行。 便捷辦法
- 第二部分:配置
1、新增遠端登入使用者(登入Mysql)
use mysql;
GRANT ALL PRIVILEGES ON*.* TO 'root'@'%' IDENTIFIED BY 'FengZe123' WITH GRANT OPTION;
注意:
問題:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解決辦法:
1.ALTER USER USER() IDENTIFIED BY 'FengZe123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密碼' WITH GRANT OPTION;
2、建立使用者時報錯:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
報錯原因:密碼強度不夠。
解決方法:(該賬號為測試賬號,所以採用降低密碼策略強度)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> 再用1的方法;
複製程式碼
2、檢查使用者表,重新整理記憶體許可權
select host, user from user;
FLUSH PRIVILEGES; 退出Mysql;
3、設定防火牆(CentOS7 不推薦)
vi /etc/sysconfig/iptables
在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,新增
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重啟防火牆
service iptables restart
注:
centos7使用的是firewall防火牆
systemctl stop firewalld.service #停止
systemctl disable firewalld.service #禁用
複製程式碼
4、設定字元編碼集和區分大小寫
4.1修改mysql配置檔案(設定字元編碼集)
預設位置:/etc/my.cnf
進入etc資料夾>>vim my.cnf
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
建立資料庫:create database 名字;
建立表格:create table(名字+類性);
檢視資料庫:show databases;