本次操作在OpenStack虚拟机192.168.0.230上进行操作,hostname为:host-172-16-5-7
从MySQL官网上下载最新的mysql安装包mysql-5.7.17-Linux-glibc2.5-x86_64.tar.gz
下载地址:
//dev.mysql.com/downloads/file/?id=467556
注意,一定要下载.tar.gz,不要下载那个.tar的包
将安装包上传到/opt目录下:
[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
整个安装过程参考如下文档进行:
//dev.mysql.com/doc/refman/5.7/en/binary-installation.html
yum search libaio # search for info yum install libaio # install library
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
如果这一步报错如下:
[ERROR] --initialize specified but the data directory has files in it. Aborting.
解决方案:
rm -rf /var/lib/mysql/
重新执行上面的,提示生成了一个临时密码:
2017-01-03T09:12:33.748807Z 1 [Note] A temporary password is generated for root@localhost: =*-gFoje>1Pr
执行这一步应该生成一个data目录,如果没有生成,那一定是因为系统中存在已经安装好了的mysql,先按照步骤2卸载掉,然后重新执行
bin/mysqld --initialize --user=mysql bin/mysql_ssl_rsa_setup chown -R root . chown -R mysql data mysql-files bin/mysqld_safe --user=mysql &
下面这一步可选
cp support-files/mysql.server /etc/init.d/mysqld
修改/usr/local/mysql/support-files/my-default.cnf
basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306
改完之后复制一份到/etc/目录下,重命名为my.cnf
cp my-default.cnf /etc/my.cnf
添加mysql环境变量
vim /etc/profile export MYSQL_HOME=/usr/local/mysql export PATH=$MYSQL_HOME/bin:$PATH source /etc/profile
service mysqld start
启动成功:
[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 ]
执行这一步的时候有可能会导致启动不成功,错误信息大概如下:
MySQL: Starting MySQL….. ERROR! The server quit without updating PID file
可参照如下链接解决:
//icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file/
如果不愿意麻烦,可以直接重启机器也可以解决该问题
至此,mysql就安装好并启动成功了。
采用
mysql -uroot -p
登录的时候,输入前面记录的root密码,提示密码不正确,没办法,我们只好自己去修改root密码了
具体步骤如下:
step1:
vim /etc/my.cnf
在[mysqld]下添加一行skip-grant-tables
step2:
service mysqld restart后,即可直接用mysql进入
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后以后在通过如下修改一次密码,否则无法进行其他操作:
mysql> SET PASSWORD = PASSWORD('mysql');
step5:
在sql控制台执行show databases;结果如下:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
附:参考文档,感谢你们的分享,正是因为你们的经验,让我能够快速解决安装过程中遇到的各种问题:
//www.cnblogs.com/tuhooo/p/5189236.html
//icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file/
原文来自:
本文地址://lrxjmw.cn/centos-install-mysql-5-7-17.html编辑:岳永,审核员:冯振华
本文原创地址://lrxjmw.cn/centos-install-mysql-5-7-17.html编辑:public,审核员:暂无