轉自:http://www.2cto.com/database/201701/583478.htmlhtml
另外的參考:http://www.jb51.net/article/109151.htmnode
http://blog.csdn.net/live006/article/details/53725666mysql
https://wenku.baidu.com/view/b257f45303768e9951e79b89680203d8ce2f6a2b.htmllinux
http://www.xker.com/page/e2015/07/211127.html MySQL 5.7.17的新特性sql
本次操做在OpenStack虛擬機192.168.0.230上進行操做,hostname爲:host-172-16-5-7vim
從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目錄下:wordpress
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.htmlui
1
2
|
yum search libaio # search
for
info
yum install libaio # install library
|
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
|
若是這一步報錯以下:spa
1
|
[ERROR]
--initialize specified but the data directory has files in it. Aborting.
|
解決方案:.net
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
|
修改/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
|
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就安裝好並啓動成功了。
採用
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)
|