從MySQL官網上下載最新的mysql安裝包mysql-5.7.17-Linux-glibc2.5-x86_64. tar.gz
注意,一定要下載.tar.gz,不要下載那個.tar的包
將安裝包上傳到/opt目錄下:
[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
yum search libaio # search for infoyum install libaio # install library
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
#修改/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
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
mysql -uroot -p
step1:
vim /etc/my.cnf
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的詳細內容。更多資訊請關注PHP中文網其他相關文章!