Redhat9.2 安裝MySQL5.0

wonth發表於2007-06-08

 一開始學習資料庫就是用的MySQL,之後就是Informix,現在是使用ORACLE,現在由於學習研究開發一個基於負載平衡的網路監控系統需要想使用MySQL,
感覺有點生疏,現就MySQL5.0在linux下安裝的經驗總結一下:
http://www.mysql.com/downloads/選擇要安裝的版本,
1.安裝MySQL需要下面兩個檔案:
  MySQL-server-4.0.16-0.i386.rpm   
  MySQL-client-4.0.16-0.i386.rpm

[root@MT src]# rpm -ivh MySQL-server-community-5.0.41-0.rhel4.i386.rpm
warning: MySQL-server-community-5.0.41-0.rhel4.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing...                ########################################### [100%]
   1:MySQL-server-community ########################################### [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 MT password 'new-password'
See the manual for more instructions.
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 at http://shop.mysql.com
Starting MySQL.......... SUCCESS!
如碰到安裝失敗(如perl(DBI)),只要安裝相應的軟體即可!
同理,安裝 MySQL-client-4.0.16-0.i386.rpm
[root@MT src]# rpm -ivh MySQL-client-4.0.16-0.i386.rpm

2.修改MySQL密碼
[root@MT src]# mysqladmin -u root password mysql

3.MySQL資料庫管理
(1)關閉與啟動
[root@MT src]# mysqladmin -u root -p shutdown
[root@MT src]# /et/init.d/mysql start
(2)更換MySQL目錄
[root@MT src]# mysqladmin -u root -p shutdown
[root@MT src]# cp /var/lib/mysql /home/mysql/5.0/
[root@MT src]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@MT src]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@MT src]# vi /etc/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
##Modified content MartriWang@gmail.com
#socket         = /var/lib/mysql/mysql.sock
socket          = /home/mysql/5.0/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
#socket         = /var/lib/mysql/mysql.sock
##Modified content MartriWang@gmail.com
socket          = /home/mysql/5.0/mysql/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

[root@MT src]# vi /etc/init.d/mysql
# The following variables are only set for letting mysql.server find things.

# Set some defaults
pid_file=
server_pid_file=
use_mysqld_safe=1
user=mysql
if test -z "$basedir"
then
  basedir=/
  bindir=/usr/bin
  if test -z "$datadir"
  then
##Modified content MartriWang@gmail.com
#    datadir=/var/lib/mysql
     datadir=/home/mysql/5.0/mysql

[root@MT src]#/etc/init.d/mysql start

(3)MySQL目錄
資料庫目錄:/var/lib/mysql/(可更改,前面已經介紹)
配置檔案:/usr/share/mysql(mysql.server命令及配置檔案)
相關命令:/usr/bin(mysqladmin mysqldump等命令)
啟動指令碼:/etc/rc.d/init.d/(ln -s /etc/init.d/)(啟動指令碼檔案mysql的目錄)

(4)備份與恢復
備份:[root@MT src]#mysqldump -u root -p --opt mysql > mysql_back
恢復:[root@MT src]#mysql -u root -p mysql < mysql_back

相關文章