centos7安裝mysql5.7
我打算在我的centos7.2上面裝一個mysql5.7,我選擇編譯安裝
1 要安裝,首先要有安裝包,下載去
因為mysql5.7要求boost,所以建議大家盡量選擇自帶boost的mysql源碼包下載來安裝,這樣就不用麻煩單獨安裝boost了.我下載的是mysql-boost-5.7.18.tar.gz
[root@python ~]# ll mysql-boost-5.7.18.tar.gz
-rw-r--r--. 1 root root 61612105 11月 9 2017 mysql-boost-5.7.18.tar.gz
2 檢查系統有沒有安裝mysql和boost
[root@python ~]# rpm -qa | grep boost
[root@python ~]# rpm -qa | grep mysql
3 安裝mysql所需的一些依賴包
[root@python ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel
...........................作為依賴被升級:
libdb.x86_64 0:5.3.21-20.el7
libdb-utils.x86_64 0:5.3.21-20.el7
libstdc++.x86_64 0:4.8.5-16.el7
完畢!
4 安裝了依賴包,就可以開始安裝我們的mysql了.
1) 創建mysql用戶和組
為了安全起見,mysql用戶不登錄,而且mysql作為系統服務,指定mysql用戶的群組為mysql群組
[root@python ~]# groupadd mysql;useradd -r -g mysql -s /bin/false mysql
useradd 的-r參數是創建系統賬號,-g指定用戶所屬組為mysql,-s /bin/false 指定用戶的shell為禁止login,其實這裏還可以設置為/sbin/nologin.
/bin/false是最嚴格的禁止login選項,一切服務都不能用。
/sbin/nologin只是不允許login系統.
當用戶配置成/sbin/nologin時,如果再使用該用戶ssh到linux操作系統,會提示#This account is currently not available.
當用戶配置成/bin/false時,用戶不能登錄,使用ssh之後不會有任何提示,用戶切換不過去.
2) 創建數據目錄
[root@python ~]# mkdir -p /data/mysql/data
3) 解壓包
[root@python ~]# tar -zxvf mysql-boost-5.7.18.tar.gz
.........................
4) 編譯
[root@python mysql-5.7.18]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost;make;make install
.......................
哎,因為我是用渣配置的虛擬機,編譯搞去我一個多小時.
編譯安裝完成以後,下面我們開始為使用做準備
5) 初始化
把mysql安裝目錄的所屬用戶和組改成mysql
[root@python mysql-5.7.18]# cd /usr/local/mysql
[root@python mysql]# pwd
/usr/local/mysql
[root@python mysql]# chown -R mysql .
[root@python mysql]# chgrp -R mysql .
[root@python mysql]#
做好了上面的,就開始初始化了,因為生產環境中,經常會要求開啟ssl功能,我這裏初始化就開啟了
[root@python mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
2017-11-10T11:41:27.358625Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-10T11:41:29.728684Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-10T11:41:30.113932Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-10T11:41:30.796879Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 18512606-c60c-11e7-b780-000c294e66bd.
2017-11-10T11:41:30.924616Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2017-11-10T11:41:30.929250Z 1 [Note] A temporary password is generated for root@localhost: gDqqGu8uer+a
6) 把mysql添加到系統服務
[root@python mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@python mysql]# chmod a+x /etc/init.d/mysqld
[root@python mysql]#
7) 替換配置文件:
[root@python support-files]# cp /etc/my.cnf /etc/my.cnf.bak
[root@python support-files]# cp my-default.cnf /etc/my.cnf
my.cnf my.cnf.bak my.cnf.d/
[root@python support-files]# cp my-default.cnf /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y
[root@python support-files]#
8) 賦予權限:
[root@python sys]# chown -R mysql.mysql /data/mysql/
[root@python sys]# chown -R mysql.mysql /var/run/mysql/
[root@python sys]# chown -R mysql.mysql /var/lib/mysql/
[root@python sys]# chown -R mysql.mysql /var/log/mysql/
[root@python sys]# chown -R mysql.mysql /data/mysql/
9) 啟動mysql:
[root@python sys]# service mysqld start
Starting MySQL.Logging to ‘/var/log/mysql/mysql.log‘.
. SUCCESS!
10) 連接到mysql:
[root@python bin]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
這是由於我們連接數據庫使用的主機名參數為“localhost”,或者未使用主機名參數、服務器默認使用“localhost”做為主機名。 使用主機名參數為“localhost”連接mysql服務端時,mysql客戶端會認為是連接本機,所以會嘗試以socket文件方式進行連接(socket文件連接方式,比“ip:端口”方式效率更高),這時根據配置文件“/etc/mysql.cnf”的路徑,未找到相應的socket文件,就會引發此錯誤。
所以需要讓mysql的客戶端能找到scoket文件,這個參數在my.cnf文件裏面配置
[root@python bin]# vi /etc/my.cnf
# For advice on how to change settings please see
..............................................
[client]
socket = /var/lib/mysql/mysql.sock
[mysql]
socket = /var/lib/mysql/mysql.sock
添加配置後,重啟mysql
[root@python bin]# mysql -uroot -p
Enter password:
.................................
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>
OK,我的mysql裝好了.
下一次裝python用的mysqldb
PS:個人之見,如果有錯誤的地方,歡迎大家指正
本文出自 “一路向上” 博客,請務必保留此出處http://zhenghong.blog.51cto.com/1676992/1980743
centos7安裝mysql5.7