wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
service mysqld restart
# mysql -u root
mysql> set password for 'root'@'localhost' = password('mypasswd');
或者:ALTER user 'root'@'localhost' IDENTIFIED BY 'mypasswd'
mysql> exit
-----------------------------------------
如果忘了初始密码,
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
可以在日志文件中找到初始密码:
grep
'temporary password'
/var/log/mysqld
.log
然后修改登录mysql并修改root密码:
ALTER user 'root'@'localhost' IDENTIFIED BY 'XXXXXX';
update mysql.user set host='%' where user ='root';
ALTER user 'root'@'%' IDENTIFIED BY 'XXXXXX';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
FLUSH PRIVILEGES;
--mysql8.0要修改密码加密规则
update mysql.user set plugin='mysql_native_password', authentication_string='' where user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'XXXXXX';
重启MySQL
service mysqld restart
防火墙开放端口:
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload
---------------------------------------
修改mysql默认字符集
1、 处理mysql的字符集,通过show variables like 'character%';命令确认。
vim /etc/my.cnf
[mysqld]
character-set-server=utf8
default-time-zone='+08:00'
[mysql]
default-character-set=utf8
然后重启mysql:service mysqld restart