linux下mysql安裝配置菜鳥篇

來源:互聯網
上載者:User

1、下載MySQL的安裝檔案
安裝MySQL需要下面兩個檔案:
MySQL-server-4.0.23-0.i386.rpm  
MySQL-client-4.0.23-0.i386.rpm
為:http://www.mysql.com/downloads/mysql-4.0.html,開啟此網頁,下拉網頁找到“Linux x86 RPM downloads”項,找到“Server”和“Client programs”項,下載需要的上述兩個rpm檔案。
2、安裝MySQL
rpm檔案是Red Hat公司開發的軟體安裝包,rpm可讓Linux在安裝軟體包時免除許多複雜的手續。該命令在安裝時常用的參數是 –ivh ,其中i表示將安裝指定的rmp軟體包,V表示安裝時的詳細資料,h表示在安裝期間出現“#”符號來顯示目前的安裝過程。這個符號將持續到安裝完成後才停 止。
1)安裝伺服器端
在有兩個rmp檔案的目錄下運行如下命令:
[root@test1 local]# rpm -ivh MySQL-server-4.0.23-0.i386.rpm
顯示如下資訊。
warning: MySQL-client-4.0.23-0.i386.rpm
signature: NOKEY, key ID 5072e1f5
Preparing...       ########################################### [100%] 本文來自無涯教程網:http://w
1:MySQL-server     ########################################### [100%]
。。。。。。(省略顯示)
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h test1 password 'new-password'
。。。。。。(省略顯示)
Starting mysqld daemon with databases from /var/lib/mysql
如出現如上資訊,服務端安裝完畢。測試是否成功可運行netstat看Mysql連接埠是否開啟,如開啟表示服務已經啟動,安裝成功。Mysql預設的連接埠是3306。
[root@test1 local]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address      Foreign Address     State   
tcp  0  0 0.0.0.0:3306     0.0.0.0:*      LISTEN   
上面顯示可以看出MySQL服務已經啟動。
2)安裝用戶端
運行如下命令:
[root@test1 local]# rpm -ivh MySQL-client-4.0.23-0.i386.rpm
warning: MySQL-client-4.0.23-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 本文來自無涯教程網:http://www.wuyapc.com
Preparing...    ########################################### [100%]
1:MySQL-client  ########################################### [100%]
顯示安裝完畢。
用下面的命令串連mysql,測試是否成功。
三、登入MySQL
登入MySQL的命令是mysql, mysql 的使用文法如下:
mysql [-u username] [-h host] [-p[password]] [dbname]
username 與 password 分別是 MySQL 的使用者名稱與密碼,mysql的初始管理帳號是root,沒有密碼,注意:這個root使用者不是Linux的系統使用者。MySQL預設使用者是root,由於 初始沒有密碼,第一次進時只需鍵入mysql即可。
[root@test1 local]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.16-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
出現了“mysql>”提示符,恭喜你,安裝成功!
增加了密碼後的登入格式如下:
mysql -u root -p
Enter password: (輸入密碼)

其中-u後跟的是使用者名稱,-p要求輸入密碼,斷行符號後在輸入密碼處輸入密碼。
注意:這個mysql檔案在/usr/bin目錄下,與後面講的開機檔案/etc/init.d/mysql不是一個檔案。

四、MySQL的幾個重要目錄
MySQL安裝完成後不象SQL Server預設安裝在一個目錄,它的資料庫檔案、設定檔和命令檔案分別在不同的目錄,瞭解這些目錄非常重要,尤其對於Linux的初學者,因為 Linux本身的目錄結構就比較複雜,如果搞不清楚MySQL的安裝目錄那就無從談起深入學習。
下面就介紹一下這幾個目錄。
1、資料庫目錄
/var/lib/mysql/
2、設定檔
/usr/share/mysql(mysql.server命令及設定檔)
3、相關命令
/usr/bin(mysqladmin mysqldump等命令)
4、啟動指令碼
/etc/rc.d/init.d/(啟動指令檔mysql的目錄)
五、修改登入密碼
MySQL預設沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。
1、命令
usr/bin/mysqladmin -u root password 'new-password'
格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼
2、例子
例1:給root加個密碼123456。
鍵入以下命令 :
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456 本文來自無涯教程網:http://www.wuyapc.com
註:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。
3、測試是否修改成功
1)不用密碼登入
[root@test1 local]# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
顯示錯誤,說明密碼已經修改。
2)用修改後的密碼登入
[root@test1 local]# mysql -u root -p
Enter password: (輸入修改後的密碼123456)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.16-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
成功!
這是通過mysqladmin命令修改口令,也可通過修改庫來更改口令。
六、啟動與停止
1、啟動
MySQL安裝完成後開機檔案mysql在/etc/init.d目錄下,在需要啟動時運行下面命令即可。
[root@test1 init.d]# /etc/init.d/mysql start
2、停止
/usr/bin/mysqladmin -u root -p shutdown
3、自動啟動
1)察看mysql是否在自動啟動列表中
[root@test1 local]# /sbin/chkconfig –list
2)把MySQL添加到你系統的啟動服務組裡面去
[root@test1 local]# /sbin/chkconfig – add mysql
3)把MySQL從啟動服務組裡面刪除。
[root@test1 local]# /sbin/chkconfig – del 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.