Linux 安裝 mysql

來源:互聯網
上載者:User

標籤:mysqld   scripts   file   echo   aries   chmod   linux   添加使用者   alt   

1、下載

 :http://dev.mysql.com/downloads/mysql/5.6.html#downloads

 下載版本:我這裡選擇的5.6.33,通用版,linux下64位

 也可以直接複製64位的,通過命令下載:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

2、解壓

1234 #解壓tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz#複製解壓後的mysql目錄cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql

3、添加使用者組和使用者

1234 #添加使用者組groupadd mysql#添加使用者mysql 到使用者組mysqluseradd -g mysql mysql

4、安裝

123456789101112131415161718192021222324252627282930 cd /usr/local/mysql/mkdir ./data/mysqlchown -R mysql:mysql ././scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysqlcp support-files/mysql.server /etc/init.d/mysqldchmod 755 /etc/init.d/mysqldcp support-files/my-default.cnf /etc/my.cnf #修改啟動指令碼vi /etc/init.d/mysqld #修改項:basedir=/usr/local/mysql/datadir=/usr/local/mysql/data/mysql #啟動服務service mysqld start #測試連接./mysql/bin/mysql -uroot #加入環境變數,編輯 /etc/profile,這樣可以在任何地方用mysql命令了export PATH=$PATH:/usr/local/mysql/bin
  #啟動mysqlservice mysqld start#關閉mysqlservice mysqld stop#查看運行狀態service mysqld status

5、錯誤

  5.1 sqlyog串連時,報1130錯誤,是由於沒有給遠端連線的使用者權限問題

  解決1:更改 ‘mysql’資料庫‘user’表‘host’項,從‘localhost’改成‘%’。

use mysql;select ‘host‘ from user where user=‘root‘; update user set host = ‘%‘ where user =‘root‘;flush privileges; 

  解決2:直接授權

  

 GRANT ALL PRIVILEGES ON *.* TO ‘root’@‘%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;

 

  5.2 安裝時的一些錯誤

   

 -bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 沒有那個檔案或目錄    解決: yum -y install perl perl-devel    Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

 

   

 解決:yum -y install libaio-devel

  

6、其他

  6.1 配置環境變數

   

 vi + /etc/profile    export PATH=....:/usr/local/mysql/bin

7 mysql 開啟服務自啟動

命令echo "service mysqld start" >> /etc/rc.local

或者進入/etc/目錄,直接vim rc.local編輯rc.local檔案,在最後一行添加“service mysqld start”,儲存退出

 

 

8 mysql初始化密碼

因為mysql剛安裝好是沒有密碼的,所以我們要將其設定密碼

⑴、剛安裝時,root使用者是空的,需要修改密碼:  ①mysqladmin -u root password ‘new-password’  ②或者,登陸後,直接修改使用者表裡的密碼     mysql -u root    #用root使用者登入    1. select user,host,password from mysql.user;    查看資料庫的使用者    2. use mysql    #切換到mysql表       set password for [email protected]=password(‘123456‘);    #設定指定網域名稱下root帳號的密碼       set password for [email protected]網域名稱=password(‘123456‘);    3.或者,更常見的sql操作:       update user set password=password(‘123456‘) where user=‘[email protected]’;⑵、匿名使用者是危險的      delete from mysql.user where user=‘‘;    #刪除匿名使用者⑶、退出mysql:  exit;

 

測試

[[email protected] ~]mysql -u root #匿名登入,已設定密碼或者刪除了匿名使用者,登陸失敗[[email protected] ~]mysql -u root -p  #通過密碼用root登入Enter password: #在這裡輸入密碼123456[[email protected] ~]mysql -u root -p 123456  #顯示密碼登陸

 

 

9 設定本機遠端存取遠程伺服器的mysql

NaviCat遠端連線的許可權問題

遠程登入會出現如下提示: 
1103 - host xxx.xxx.xxx.xx is not allowed to connec to this mysql server.或1045 - Access denied for user ‘root‘@‘192.168.1.11‘ (using password: YES).

解決方案:

//mysql訪問grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;#其實就是許可權問題,設定root在所有網域名稱(%表示任何地址)登陸時,賦給所有許可權,密碼123456。根據需要可設定更嚴格些。

上面的123456是你自己設定的密碼,遠程密碼應該要嚴格一點,否則會不惡意攻破

 

Linux 安裝 mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.