搞定linux上MySQL資料庫編程(一):linux上源碼安裝MySQL資料庫

1. 首先下載源碼包:

ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.72.tar.gz

2. 使用如下命令檢查系統中是否已安裝mysql:

rpm -qa |  grep mysql

3.沒有安裝則解壓安裝包然後進入該目錄:

cd mysql

分別依次執行如下操作:

./configure --prefix=/usr/local/mysql --with-charset=gbk
make
make install

4.添加MySQL配置文件

如果你想要設置一個選項文件,使用support-files目錄中的一個作為模板。在這個目錄中有4個模板文件,是根據不同機器的內存定制的。

 

#cp support-files/my-medium.cnf /etc/my.cnf

 

5.設置開機自動啟動

 

#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chmod 755 /etc/init.d/mysqld
#chkconfig –-add mysqld
#chkconfig –-level 345 mysqld on

 

6.創建mysql權限表:

cd /usr/local/mysql
scripts/mysql_install_db --user=mysql

7.最後將安裝目錄的擁有者和所屬組分別變更為root和mysql, 命令為:

chown -R root
chgrp -R mysql

8.測試成功否?
第一次運行會彈出如下信息,說明安裝成功:

#/etc/rc.d/init.d/mysqld start

Initializing MySQL database:  Installing MySQL system tables... 
OK 
Filling help tables... 
OK 
 
To start mysqld at boot time you have to copy 
support-files/mysql.server to the right place for your system 
 
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.localdomain password 'new-password' 
 
Alternatively you can run: 
/usr/bin/mysql_secure_installation 
 
which will also give you the option of removing the test 
databases and anonymous user created by default.  This is 
strongly recommended for production servers. 
 
See the manual for more instructions. 
 
You can start the MySQL daemon with: 
cd /usr ; /usr/bin/mysqld_safe & 
 
You can test the MySQL daemon with mysql-test-run.pl 
cd /usr/mysql-test ; perl mysql-test-run.pl 
 
Please report any problems with the /usr/bin/mysqlbug script! 
 
                                                           [  OK  ] 
Starting mysqld:                                           [  OK  ] 

9.查看3306端口是否啟動:

# netstat -altnp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      6946/mysqld        
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1892/rpcbind        
tcp        0      0 192.168.122.1:53            0.0.0.0:*                   LISTEN      2726/dnsmasq        

10.為瞭安全,需要修改密碼,默認為空:

mysqladmin -u root password shallnet

至此,可以在命令行上面使用新的密碼登錄mysql瞭。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *