CentOS6.5下安装MySql5.7.17
转自:http://www.2cto.com/database/201701/583478.html
另外的参考:http://www.jb51.net/article/109151.htm
http://blog.csdn.net/live006/article/details/53725666
https://wenku.baidu.com/view/b257f45303768e9951e79b89680203d8ce2f6a2b.html
http://www.xker.com/page/e2015/07/211127.html MySQL 5.7.17的新特性
CentOS6.5下安装MySql5.7.17
0.操作说明
本次操作在OpenStack虚拟机192.168.0.230上进行操作,hostname为:host-172-16-5-7
1.下载安装包
从Mysql官网上下载最新的Mysql安装包mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
下载地址:
http://dev.mysql.com/downloads/file/?id=467556
注意,一定要下载.tar.gz,不要下载那个.tar的包
将安装包上传到/opt目录下:
2.检查库文件是否存在,如果存在则删除
1
2
3
4
5
6
|
[root@host-172-16-5-7 ~]# rpm -qa | grep mysql mysql-libs-5.1.73-3.el6_5.x86_64 [root@host-172-16-5-7 ~]# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps /sbin/ldconfig: File /usr/lib64/libpq.so.5.8 is empty, not checked. [root@host-172-16-5-7 ~]# rpm -qa | grep mysql [root@host-172-16-5-7 ~]# |
整个安装过程参考如下文档进行:
http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
3.Mysql依赖于libaio库
1
2
|
yum search libaio # search for info yum install libaio # install library |
4.分别执行以下步骤安装Mysql
1
2
3
4
5
6
7
8
9
10
11
|
groupadd mysql useradd -r -g mysql -s /bin/ false mysql cd /usr/ local tar -zxvf /opt/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /opt/ ln -s /opt/mysql-5.7.17-linux-glibc2.5-x86_64 mysql cd mysql mkdir mysql-files chmod 750 mysql-files chown -R mysql . chgrp -R mysql . bin/mysqld --initialize --user=mysql |
如果这一步报错如下:
1
|
[ERROR] --initialize specified but the data directory has files in it. Aborting. |
解决方案:
1
|
rm -rf /var/lib/mysql/ |
重新执行上面的命令,提示生成了一个临时密码:
1
|
2017-01-03T09:12:33.748807Z 1 [Note] A temporary password is generated for root@localhost: =*-gFoje>1Pr |
执行这一步应该生成一个data目录,如果没有生成,那一定是因为系统中存在已经安装好了的mysql,先按照步骤2卸载掉,然后重新执行
1
|
bin/mysqld --initialize --user=mysql |
1
2
3
4
|
bin/mysql_ssl_rsa_setup chown -R root . chown -R mysql data mysql-files bin/mysqld_safe --user=mysql & |
下面这一步可选
1
|
cp support-files/mysql.server /etc/init.d/mysqld |
5.安装后的配置
修改/usr/local/mysql/support-files/my-default.cnf
1
2
3
|
basedir = /usr/ local /mysql datadir = /usr/ local /mysql/data port = 3306 |
改完之后复制一份到/etc/目录下,重命名为my.cnf
1
|
cp my- default .cnf /etc/my.cnf |
添加mysql环境变量
1
2
3
4
|
vim /etc/profile export MYSQL_HOME=/usr/ local /mysql export PATH=$MYSQL_HOME/bin:$PATH source /etc/profile |
6.启动mysql
1
|
service mysqld start |
启动成功:
1
2
3
4
5
|
[root@ambari support-files]# service mysqld start Starting MySQL.Logging to '/usr/local/mysql/data/ambari.err' . . [ OK ] [root@ambari support-files]# service mysqld status MySQL running (8010) [ OK ] |
执行这一步的时候有可能会导致启动不成功,错误信息大概如下:
1
|
MySQL: Starting MySQL….. ERROR! The server quit without updating PID file |
可参照如下链接解决:
https://icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file/
如果不愿意麻烦,可以直接重启机器也可以解决该问题
至此,mysql就安装好并启动成功了。
7.修改root密码:
采用
1
|
mysql -uroot -p |
登录的时候,输入前面记录的root密码,提示密码不正确,没办法,我们只好自己去修改root密码了
具体步骤如下:
step1:
1
|
vim /etc/my.cnf |
在[mysqld]下添加一行skip-grant-tables
step2:
service mysqld restart后,即可直接用mysql进入
1
2
3
|
mysql> update mysql. user set authentication_string= password ( 'root' ) where user = 'root' and Host = 'localhost' ; mysql> flush privileges ; mysql> quit; |
step3:
将/etc/my.cnf文件还原,重新启动mysql:service mysqld restart,这个时候可以使用mysql -u root -p'root'进入了
step4:
进入到sql后以后在通过如下命令修改一次密码,否则无法进行其他操作:
1
|
mysql> SET PASSWORD = PASSWORD ( 'mysql' ); |
step5:
在sql控制台执行show databases;结果如下:
1
2
3
4
5
6
7
8
9
10
|
mysql> show databases; + --------------------+ | Database | + --------------------+ | information_schema | | mysql | | performance_schema | | sys | + --------------------+ 4 rows in set (0.00 sec) |