MYSQL-5.7
1、yum安装
1)卸载mariadb
rpm -qa | grep mariadb | xargs rpm -e --nodeps
2)下载msql5.7 yum源
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
3)安装yum源
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
4)安装mysql
yum -y install mysql-server
5)启动mysql
service mysqld start
6)查看root用户密码
grep 'temporary password' /var/log/mysqld.log
7)执行mysql初始化脚本
mysql_secure_installation
8)输入新密码(至少12个字符,至少包含一个大写字母有,一个小写字母,一个数字,一个特殊字符)
9)配置root用户远程访问权限
mysql> grant all privileges on *.* to 'root' @'%' identified by '@123456Qa';
mysql> flush privileges;
10)安装mysql驱动
(1)将mysql-connector-java-5.1.27-bin.jar拷贝到/usr/share/java路径下,并重命名
mv mysql-connector-java-5.1.27-bin.jar mysql-connector-java.jar
(2)分发驱动
xsync /usr/share/java
2、rpm安装
- 卸载mariadb
rpm -qa | grep mariadb | xargs rpm -e --nodeps
- 导入rpm包
- 检查
必须有如下两个包
rpm -qa|grep libaio
rpm -qa|grep net-tools
- 授权 chmod -R 777 /tmp
- 安装mysql
rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
- 查看版本
mysqladmin --version
- 初始化服务
mysqld --initialize --user=mysql
- 查看密码
cat /var/log/mysqld.log
root@localhost: 后面就是初始化的密码
- 相关服务
启动:systemctl start mysqld.service
停止:systemctl stop mysqld.service
- 登录修改密码
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED BY 'new_password';
- 修改字符集
vim /etc/my.cnf
在最后加上中文字符集配置
character_set_server=utf8
并重启
systemctl restart mysqld.service
- 授权远程连接
grant all privileges on . to root@'%' identified by 'root';
3、问题
1)Access denied for user 'root'@'localhost' (using password: YES)
1.,vi /etc/my.cnf
在最尾部加上
skip-grant-tables
保存
3,启动mysql
systemctl start mysqld.service
4,登录musql
mysql -u root
此处注意不要加-p
5,修改密码,mysql5.7用此语法
use mysql ;
update mysql.user set authentication_string=password('123456') where user='root' ;
6,回到第二步骤去掉加上的
skip-grant-tables
保存 重启mysql就ok了
2)密码安全策略
validate_password_policy类型
Policy | Tests Performed |
---|---|
0 or LOW |
Length |
1 or MEDIUM |
Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG |
Length; numeric, lowercase/uppercase, and special characters; dictionary file |
修改策略方式
set global validate_password_policy=0;