linux下安裝mysql的方法

2012-7-27 6:11:35 | tags mysql   | views

1.到mysql的網站(必須到官方網站下載,防止數據被修改,纂改過)下載四個必須rpm 安裝包:
http://dev.mysql.com/downloads/mysql/5.0.html#linux-rhel5-ia64-rpms

MySQL-client-5.1.16-0.glibc23.i386.rpm
MySQL-devel-5.1.16-0.glibc23.i386.rpm
-
 

MySQL-server-5.1.16-0.glibc23.i386.rpm
MySQL-shared-5.1.16-0.glibc23.i386.rpm

2. 通過ssh遠程控制工具傳到服務器上,放在適當的目錄下(如:/opt/mysql/mysql5.1.16)
3.進入目錄(/opt/mysql/mysql5.1.16)下安裝msyql:
rpm 文件是Red Hat公司開發軟件安裝包,rpm可讓Linux在安裝軟件包時免除許多復雜的手續。該命令在安裝時常用的參數是 –ivh ,其中i表示將安裝指定的rmp軟件包,V表示安裝時的詳細信息,h表示在安裝期間出現"#"符號來顯示目前的安裝過程。這個符號將持續到安裝完成后才停止。

[[email protected] mysql5.1.16]# rpm –ivh MySQL-client-5.1.16-0.glibc23.i386.rpm
[[email protected] mysql5.1.16]# rpm –ivh MySQL-devel-5.1.16-0.glibc23.i386.rpm
[[email protected] mysql5.1.16]# rpm –ivh MySQL-shared-5.1.16-0.glibc23.i386.rpm
[[email protected] mysql5.1.16]# rpm –ivh MySQL-server-5.1.16-0.glibc23.i386.rpm

 顯示如下信息

warning: MySQL-server-5.1.16-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost password 'new-password'
See the manual for more instructions.

NOTE: If you are upgrading from a MySQL <= 3.22.10 you should run
the /usr/bin/mysql_fix_privilege_tables. Otherwise you will not be
able to use the new GRANT command!

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses athttps://order.mysql.com
Starting MySQL...................................[失敗]

4.查看已安裝的包
[[email protected] mysql5.1.20]# rpm -qa | grep -i mysql
或者 [[email protected] mysql5.1.20]# rpm -qa | grep mysql

MySQL-devel-5.1.20-0.glibc23
MySQL-shared-5.1.20-0.glibc23
MySQL-client-5.1.20-0.glibc23
MySQL-server-5.1.20-0.glibc23

5.查看[[email protected] /]# locate mysql.server 的路徑
/usr/share/man/man1/mysql.server.1.gz
/usr/share/mysql/mysql.server
復制并更名 [[email protected] /]#cp /usr/share/mysql/mysql.server /etc/init.d/mysqld
6.查看[[email protected] /]# locate my-huge.cnf 的路徑
/usr/share/doc/MySQL-server-5.1.16/my-huge.cnf
/usr/share/mysql/my-huge.cnf
復制并更名[[email protected] /]#cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
7.啟動服務:
service mysqld start
Starting MySQL [ OK ]
啟動成功!恭喜~~~
8.編輯vi /etc/my.cnf 這個文件,設置字符集,支持國際化.

default-character-set=utf8 //在此添加字符集
# Here follows entries for some specific programs

# The MySQL server
[mysqld] port = 3306
#socket = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M


default-character-set=utf8 //在此添加字符集
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 16

先按Esc, 再同時按Shift + ; 再輸入wq! (推出并保存)
呵呵! 字符集就配置好了~~~
9.MySQL默認的數據文件存儲目錄為/var/lib/mysql。假如要把目錄移到/qudeedata/dbdata/mysql5.1.16下需要進行下面幾步:
(1)、/qudeedata/dbdata目錄下建立mysql5.1.16目錄
cd /qudeedata/dbdata
mkdir mysql5.1.16
(2)、把MySQL服務進程停掉:
service mysqld stop
(3)、把/var/lib/mysql整個目錄移到/qudeedata/dbdata/mysql5.1.16
mv /var/lib/mysql /qudeedata/dbdata/mysql5.1.16
這樣就把MySQL的數據文件移動到了/qudeedata/dbdata/mysql5.1.16 下
(4)、編輯MySQL的配置文件/etc/my.cnf
為保證MySQL能夠正常工作,需要指明mysql.sock文件的產生位置。修改socket=/var/lib/mysql/mysql.sock一行中等號右邊的值為:
/qudeedata/dbdata/mysql5.1.16/mysql/mysql.sock 。操作如下:
命令: vi  my.cnf    (用vi工具編輯my.cnf文件,找到下列數據修改之)
# The MySQL server
[mysqld]
port   = 3306
#socket  = /var/lib/mysql/mysql.sock(原內容,為了更穩妥用"#"注釋此行)
socket  = /qudeedata/dbdata/mysql5.1.16/mysql/mysql.sock   (加上此行)
(5)、修改MySQL啟動腳本/etc/rc.d/init.d/mysqld
最后,需要修改MySQL啟動腳本/etc/rc.d/init.d/mysqld,把其中datadir=/var/lib/mysql一行中,等號右邊的路徑改成你現在的實際存放路徑:
/qudeedata/dbdata/mysql5.1.16。
[[email protected] etc]# vi /etc/rc.d/init.d/mysqld
#datadir=/var/lib/mysql    (注釋此行)
datadir=/qudeedata/dbdata/mysql5.1.16   (加上此行)
10、自動啟動
1)察看mysql是否在自動啟動列表中
[[email protected] /]# chkconfig –list
2)把MySQL添加到你系統的啟動服務組里面去
[[email protected] /]# chkconfig – add mysql
11.測試通過命令是否能夠啟動,停止,重啟
結果:

[[email protected] /]# service mysqld start
Starting MySQL [ OK ]
[[email protected] /]# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL [ OK ]
[[email protected] /]# service mysqld stop
Shutting down MySQL... [ OK ]
[[email protected] /]# /etc/init.d/mysqld start
Starting MySQL [ OK ]
[[email protected] /]# /etc/init.d/mysqld restart
Shutting down MySQL... [ OK ]
Starting MySQL [ OK ]
[[email protected] /]# /etc/init.d/mysqld stop
Shutting down MySQL.. [ OK ]

證明,成功安裝mysql.注:還可以通過添加,查詢,刪除數據庫中的數據進行操作.
12.完成安裝!

    相關文章:

發表評論:

◎歡迎參與討論,請在這里發表您的看法、交流您的觀點。

手机捕鱼怎么下载
二人斗地主在线玩 单机斗地主欢乐版免费 重庆欢乐生肖开奖 快乐十分可以买大小吗 体彩停止电子投注 龙虎和怎么下注能赢 稳赚不赔的小生意 元升娱乐 通比牛牛游戏 极速3d投注技巧 福建时时玩法规则 逆袭欢乐生肖计划手机版 mgm娱乐可靠吗 大富贵看牌抢庄牛牛 大乐开奖结果查询开 时时缩水软件在线