从MySQL官网上下载最新的mysql安装包mysql-5.7.17-Linux-glibc2.5-x86_64.tar.gz
注意,一定要下载.tar.gz,不要下载那个.tar的包
将安装包上传到/opt目录下:
2.检查库文件是否存在,如果存在则删除
[root@host-172-16-5-7 ~]# rpm -qa | grep mysqlmysql-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
3.Mysql依赖于libaio库
yum search libaio # search for infoyum install libaio # install library
4.分别执行以下步骤安装Mysql
groupadd mysql useradd -r -g mysql -s /bin/false mysqlcd /usr/localtar -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 mysqlcd 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
5.安装后的配置
修改/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/profileexport MYSQL_HOME=/usr/local/mysqlexport PATH=$MYSQL_HOME/bin:$PATHsource /etc/profile
6.启动mysql
service mysqld start
启动成功:
[root@ambari support-files]# service mysqld startStarting MySQL.Logging to '/usr/local/mysql/data/ambari.err'. . [ OK ] [root@ambari support-files]# service mysqld statusMySQL running (8010) [ OK ]
执行这一步的时候有可能会导致启动不成功,错误信息大概如下:
MySQL: Starting MySQL….. ERROR! The server quit without updating PID file
7.修改root密码:
采用
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)
以上就是CentOS 6.5下怎么快速安装MySQL 5.7.17的详细内容。