一 更换yum
1备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2更新阿里yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
3 查看cd /etc/yum.repos.d/
4 yum clean all
5 yum makecache
二 下载配置mysql的yum源的rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
安装用来配置mysql的yum源的rpm包
rpm -Uvh mysql57-community-release-el6-9.noarch.rpm
安装成功后在/etc/yum.repos.d/下会多出几个mysql的yum源的配置
[root@zat2 yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo mysql-community.repo
CentOS-Base.repo.backup CentOS-Media.repo mysql-community-source.repo
三 安装mysql
[root@zat2 yum.repos.d]# rpm -qa | grep mysql
[root@zat2 yum.repos.d]# yum install mysql-community-server
四 开启mysql
[root@zat2 yum.repos.d]# service mysqld restart
停止 mysqld: [确定]
初始化 MySQL 数据库: [失败]
[root@zat2 yum.repos.d]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@zat2 yum.repos.d]# ps -ef | grep mysql
密码
[root@zat2 yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2018-07-19T20:33:49.986448Z 1 [Note] A temporary password is generated for root@localhost: efl!>rif<2xU
centos 6设置开机自启
[root@zat2 yum.repos.d]# chkconfig --add mysqld
[root@zat2 yum.repos.d]# chkconfig mysqld on
[root@zat2 yum.repos.d]# chkconfig list
[root@zat2 yum.repos.d]# chkconfig --list
五报错处理
[root@zat2 ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@zat2 ~]# vi /etc/my.cnf
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程
[root@zat2 ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@zat2 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)
第二新安装的MySQL5.7,登录时提示密码错误,安装的时候并没有更改密码,后来通过免密码登录的方式更改密码,输入update mysql.user set password=password('root') where user='root'时提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原来是mysql数据库下已经没有password这个字段了,password字段改成了
authentication_string
所以更改语句替换为update mysql.user set authentication_string=password('root') where user='root' ;即可
mysql设置密码
[root@zat2 yum.repos.d]# mysqladmin -uroot -p password 'zat'
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin:
You cannot use 'password' command as mysqld runs
with grant tables disabled (was started with --skip-grant-tables).
Use: "mysqladmin flush-privileges password '*'" instead
[root@zat2 yum.repos.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 6
Server version: 5.7.22 MySQL Community Server (GPL)
centos 7 安装mysql5.7
卸载maridb
[root@zatt ~]# yum remove mariadb*
杀死yum进程
kill -9 `ps -ef |grep yum |awk '{print $2}' `
1配置YUM源
# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
[root@zatt ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 51
mysql-tools-community/x86_64 MySQL Tools Community 63
mysql57-community/x86_64 MySQL 5.7 Community Server 267
2、安 装MySQL
shell> yum install mysql-community-server
3、启动MySQL服务
shell> systemctl start mysqld
查看MySQL的启动状态
shell> systemctl status mysqld
4、开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
5、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
[root@zatt ~]# grep 'temporary password' /var/log/mysqld.log
2018-07-18T13:24:49.210585Z 1 [Note] A temporary password is generated for root@localhost: Mq:kNQP(4?Zh
shell> mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新启动mysql服务使配置生效:
systemctl restart mysqld
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
如果忘记root密码,则按如下操作恢复:
在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。
mysql -u root
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
flush privileges