Linux安裝mysql-5.7.17

來源:互聯網
上載者:User

標籤:oca   軟連結   director   data   最好   cti   mysq   目錄許可權   找不到   

一.檢查系統是否有內建安裝MySQL1.檢查
[[email protected] ~]# rpm -qa | grep -i mysqlmysql-libs-5.1.71-1.el6.x86_64
2.卸載
[[email protected] ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64[[email protected] ~]# rpm -qa | grep -i mysqlrpm -e --noscripts MySQL-client-5.5.25a-1.rhel5rm -fr 刪除檔案
二、解壓及重新命名
[[email protected] ~]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /data/[[email protected] ~]# mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql-5.7.17
三、建立使用者和使用者組給mysql賦許可權1.建立使用者mysql,組mysql。後面mysql就使用這個使用者來運行(注意這也是mysql啟動指令碼中預設的使用者,因此最好不要改名)。
[[email protected] mysql-5.7.17]# groupadd mysql[[email protected] mysql-5.7.17]# useradd -r -g mysql mysql
 (使用-r參數表示mysql使用者是一個系統使用者,不能登入) 2.手動建立MySQL data目錄
[[email protected] data]# mkdir /data/mysql-5.7/data
3.目錄使用權限設定

將mysql及其下所有的目錄所有者和組均設為mysql:

[[email protected] mysql-5.7]# chown -R mysql:mysql /data/mysql-5.7/[[email protected] mysql-5.7]# chmod 755 /data/mysql-5.7./
四、資料庫初始化
[[email protected] bin]# ./mysqld --initialize --user=mysql --datadir=/data/mysql-5.7/data --basedir=/data/mysql-5.7

  初始化完成記錄下初始密碼,登入資料庫要用到

[email protected]: TsYB;K9rwrK6
五、配置

  將mysql/support-files下的my-default.cnf改名為my.cnf,拷到/etc下(或者考到{mysql}下,然後作一個軟連結到/etc下):

[[email protected] support-files]# cp /data/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf

  修改/etc/my.cnf中關鍵配置:

[[email protected] support-files]# vim /etc/my.cnf[mysqld] basedir = /data/mysql-5.7.17 datadir = /data/mysql-5.7.17/data port = 3306 socket = /data/mysql-5.7.17/tmp/mysql.sock

  注意,tmp目錄不存在,請建立之。

[[email protected] data]# mkdir /data/mysql-5.7.17/tmp
  六、運行  1.運行之前重新給MySQL目錄賦予許可權
[[email protected] mysql-5.7.17]# chown mysql:mysql /data/mysql-5.7/[[email protected] data]# chmod 755 /data/mysql-5.7.17/
  2.運行伺服器程式
[[email protected] bin]# ./mysqld_safe &

  

註:在這個啟動指令碼裡已預設設定--user=mysql;在指令碼末尾加&表示設定此進程為後台進程,區別就是在控制台輸入bg,即可將當前進程轉入後台,當前shell可進行其他動作。

可能會報錯:

2017-10-11T13:04:21.482778Z mysqld_safe Logging to ‘/data/mysql-5.7/data/centos.xd.err‘.2017-10-11T13:04:21.485731Z mysqld_safe The file /usr/local/mysql/bin/mysqlddoes not exist or is not executable. Please cd to the mysql installationdirectory and restart this script from there as follows:./bin/mysqld_safe&See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

說明:mysqld_safe啟動指令碼預設的從/usr/local/mysql目錄中讀取另外一個啟動指令碼mysqld,因為我的安裝目錄為/data/mysql-5.17/bin/mysqld,所以找不到相關檔案。
解決方案:

[[email protected] mysql-5.7]# mkdir -p /usr/local/mysql/bin/[[email protected] mysql-5.7]# ln -s /data/mysql-5.7/bin/mysqld /usr/local/mysql/bin/
3、設定mysql以服務運行

將{mysql}/ support-files/mysql.server 拷貝為/etc/init.d/mysql並設定運行許可權

[[email protected] data]# cp /data/mysql-5.7/support-files/mysql.server /etc/init.d/mysql[[email protected] data]#chmod +x /etc/init.d/mysql
4.啟動mysql
[[email protected] data]# /etc/init.d/mysql start

  

可能會出現錯誤:
1:Starting MySQL.Logging to ‘/data/mysqldata/localhost.localdomain.err’.
ERROR! The server quit without updating PID file (/data/mysqldata/localhost.localdomain.pid).
bin/mysqld –initialize –user=mysql 是關鍵,再重新安裝下

2:MySQL [ERROR] Table ‘mysql.user‘ doesn‘t exist
檢查/etc/my.cnf配置是否正確datadir
檢查後重新啟動

[[email protected] mysql-5.7]# /etc/init.d/mysql startStarting MySQL. SUCCESS!
5.串連資料庫
[[email protected] ~]# mysql -uroot -p

  

可能會出現錯誤:
1:-bash: mysql: command not found
將mysql/bin/mysql命令 連結到usr/bin/mysql x

[[email protected] ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

2:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
則需要在在my.cnf中填加:
[client]
socket = /data/mysql-5.7/tmp/mysql.sock

如果不行則使用軟連結:

[[email protected] tmp]# ln -s /data/mysql-5.7/tmp/mysql.sock /tmp/mysql.sock

啟動成功

[[email protected] mysql-5.7]# mysql -uroot -pEnter password: 輸入初始化資料庫時記錄的密碼Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.17 MySQL Community Server (GPL)

設定root使用者密碼

mysql> set password=password(‘123456‘);Query OK, 0 rows affected, 1 warning (0.03 sec)

給root賬戶賦予全部許可權

mysql> grant all privileges on *.* to [email protected]‘localhost‘ identified by ‘123456‘;Query OK, 0 rows affected, 1 warning (0.00 sec)

重新整理

mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

退出mysql

mysql> exit;Bye
  把mysql註冊為開機啟動的服務
#chkconfig --add mysql使用範例:chkconfig --list        #列出所有的系統服務chkconfig --add httpd        #增加httpd服務chkconfig --del httpd        #刪除httpd服務chkconfig --level httpd 2345 on        #設定httpd在運行層級為2、3、4、5的情況下都是on(開啟)的狀態chkconfig --list        #列出系統所有的服務啟動情況chkconfig --list mysqld        #列出mysqld服務設定情況chkconfig --level 35 mysqld on        #設定mysqld在等級3和5為開機運行服務,--level 35表示操作只在等級3和5執行,on表示啟動,off表示關閉chkconfig mysqld on        #設定mysqld在各等級為on,“各等級”包括2、3、4、5等級如何增加一個服務:1.服務指令碼必須存放在/etc/ini.d/目錄下;2.chkconfig --add servicename    在chkconfig工具服務列表中增加此服務,此時服務會被在/etc/rc.d/rcN.d中賦予K/S入口了;3.chkconfig --level 35 mysqld on    修改服務的預設啟動等級。
  mysql服務的開啟和關閉:
[[email protected] mysql-5.7]# /etc/init.d/mysql start[[email protected] mysql-5.7]# /etc/init.d/mysql stop或:[[email protected] mysql-5.7]# service mysql stopShutting down MySQL.. SUCCESS! [[email protected] mysql-5.7]# service mysql startStarting MySQL. SUCCESS! 
  查看MySQL的安裝目錄
[[email protected] mysql-5.7]# whereis mysqlmysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql
  查看Mysql的運行目錄
[[email protected] mysql-5.7]# which mysql/usr/bin/mysql

  

Linux安裝mysql-5.7.17

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.