通过Yum安装
- 在官网找到对应的rpm
<pre>http://dev.mysql.com/downloads/repo/yum/</pre> - 点击download进入下载
<pre>http://dev.mysql.com/downloads/file/?id=459921</pre> - 在页面底部有个名为《 No thanks, just start my download.》的链接,这个链接就是下载地址。
<pre>http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm</pre> - 在服务器上安装rpm
<pre>rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm</pre> - 更新yum
<pre>yum update</pre> - 安装mysql
<pre>yum install -y mysql-community-server</pre> - 开启mysql服务
<pre>systemctl start mysqld.service</pre> - 获取mysql默认密码
<pre>grep 'temporary password' /var/log/mysqld.log</pre>
2015-11-30T03:16:23.337689Z 1 [Note] A temporary password is generated for root@localhost: ylW?D-q+l6Ip
命令运行后得到上面一句字符串,其中ylW?D-q+l6Ip
就是密码
- mysql安全配置
<pre>mysql_secure_installation</pre>
- Enter password for user root:
输入刚刚得到的密码 - New password:
输入新的密码 - Re-enter new password:
重复输入新的密码 - Change the password for root ? ((Press y|Y for Yes, any other key for No)
是否想改变root的密码,输入Y,重复设置密码。 - Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No)
输入Y - Remove anonymous users? (Press y|Y for Yes, any other key for No)
删除匿名用户,输入Y - Disallow root login remotely? (Press y|Y for Yes, any other key for No)
是否禁止远程登录,输入N,(但事后发现还是不能远程登录,可以试试Y) - Remove test database and access to it? (Press y|Y for Yes, any other key for No)
是否删除test数据库,输入N - Reload privilege tables now? (Press y|Y for Yes, any other key for No)
是否重新加载权限表,输入Y
- 安装完成
可以通过mysql -uroot -p
登录,密码是刚刚设置的