在mysql官网找到下载地址并下载mysql的rpm包,然后使用yum安装
找到官网下载地址
1.安装库(这里的下载链接已被我提取至命令行)
$ rpm -ivh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
2.使用yum分别安装mysql服务端和客户端
$ yum install mysql-community-server
$ yum install mysql-community-client
中途会有确认提示,输入y确认
再次查看mysql服务状态
$ service mysqld status
结果:
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
3.启动mysql服务(需要root权限加sudo)
$ sudo service mysqld start
再次查看mysql服务状态
$ service mysqld status
结果:
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2017-08-03 15:03:39 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4070 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3997 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4074 (mysqld)
CGroup: /system.slice/mysqld.service
└─4074 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
4.查看mysql初始密码
$ vim /var/logs/mysqld.log
5.进入mysql
1)输入以下命令进入mysql命令行
$ mysql -u root -p
2)输入刚才看到的初始密码,成功进入mysql
此时不能进行一般操作,否则会提示:
You must reset your password using ALTER USER statement before executing this statement
输入mysql命令重置密码:
$ set password = password('1234');
注:执行此步请确保mysql中没有root之外的用户
提示:
Your password does not satisfy the current policy requirements
导致以上提示的原因是密码安全等级太低的意思
3)如果是个人测试,降低密码校验要求
$ set global validate_password_policy=0;
$ set global validate_password_length=1;
4)再次重置密码
$ set password = password('1234');
如果密码要求严格请参照重置root密码
5)退出mysql命令行
$ exit
参考文章: