CentOS 6.5下快速安裝MySQL 5.7.17

本次操做在OpenStack虛擬機192.168.0.230上進行操做,hostname爲:host-172-16-5-7html

1.下載安裝包node

從MySQL官網上下載最新的mysql安裝包mysql-5.7.17-Linux-glibc2.5-x86_64.tar.gzmysql

下載地址:linux

http://dev.mysql.com/downloads/file/?id=467556sql

注意,必定要下載.tar.gz,不要下載那個.tar的包vim

將安裝包上傳到/opt目錄下:centos

2.檢查庫文件是否存在,若是存在則刪除wordpress

[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

整個安裝過程參考以下文檔進行:ui

http://dev.mysql.com/doc/refman/5.7/en/binary-installation.htmlrest

3.Mysql依賴於libaio庫

yum search libaio  # search for info
yum install libaio # install library

4.分別執行如下步驟安裝Mysql

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

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/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
source /etc/profile

6.啓動mysql

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

可參照以下連接解決:

https://icesquare.com/wordpress/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file/

若是不肯意麻煩,能夠直接重啓機器也能夠解決該問題

至此,mysql就安裝好並啓動成功了。

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)

本文地址:http://www.linuxprobe.com/centos-install-mysql-5-7-17.html

相關文章
相關標籤/搜索