一、安装mysql
1.通过域名安装mysql
yum list | grep mysql #查看yum库中是否有mysql
需要安装如下两个:
mysql.x86_64 5.1.73-8.el6_8 base
mysql-server.x86_64 5.1.73-8.el6_8 base
yum install mysql.x86_64 mysql-server.x86_64
2.查看mysql版本
rpm -qi mysql-serverwdaw
二、配置mysql
1.启动服务
service mysqld start
2.重启服务
service mysqld restart
3.查看mysql服务是否为开机启动
chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
设置开机启动
chkconfig mysqld on
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4.给root用户设置密码
/usr/bin/mysqladmin -u root password 'new-password'
如果出现
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
方法一:
修改my.cnf,跳过密码验证
vim /etc/my.cnf
添加 skip-grant-tables
保存退出,重启mysql服务
service mysqld restart
直接输入 mysql 回车
进入mysql数据库
use mysql;
update mysql.user set authentication_string=password('newpassword') where user='root' ;
退出数据库,将添加的 skip-grant-tables 删除
重启数据库 service mysqld restart
输入 mysql -u root -p
输入密码,即可登录。
方法二
mysql5.7 会生成初始的随机root密码,一般在error_log里面
cat /var/log/mysqld.log | grep password
找到:
2018-03-24T06:19:20.327109Z 1 [Note] A temporary password is generated for root@localhost: K/=bxxxxjdj1f
就是root用户初始密码。
5.登录mysql
mysql -uroot -p
输入密码