#tar zxvf mysql-5.0.18.tar.gz
#cd mysql-5.0.18
#./configure --prefix=/usr/local/mysql --with-charset=gb2312 --with-extra-charsets=all #--prefix指定安裝目錄,讓他支持中文,支持所有語(yǔ)
#指定安裝路徑為/usr/local/mysql,配置文件存放目錄/etc,數據庫存儲目錄/var/lib/mysql
./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql
?。ü﹨⒖迹?br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; "> #make
#make install
#make clean
#groupadd mysql
#useradd -g mysql mysql (第一個(gè)mysql是組,第二個(gè)mysql是用戶(hù))
#cd /usr/local/mysql
#cp usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf (或cp /root/mysql-5.0.18
/support-files/my-huge.cnf.sh /etc/my.cnf 網(wǎng)絡(luò )上是寫(xiě)括號內的,但我試了不行#根據自己主機的情況復制my-*.cnf的一個(gè),huge是應用于內存在2G以上的情況。)
#bin/mysql_install_db --user=mysql #建立基本數據庫,必須指明為mysql用戶(hù),只有這一步才能在usr/local/mysql下出現var目錄。出現如下:
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
Unknown suffix
'@' used for variable 'port' (value
'@MYSQL_TCP_PORT@')
080425 4:38:40 /usr/local/mysql/libexec/mysqld: Error while setting value
'@MYSQL_TCP_PORT@' to 'port'
Installation of grant tables failed!
Examine the logs in /usr/local/mysql/var for more information.
You can also try to start the mysqld daemon with:
/usr/local/mysql/libexec/mysqld --skip-grant &
You can use the command line tool
/usr/local/mysql/bin/mysql to connect to the mysql
database and look at the grant tables:
shell> /usr/local/mysql/bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /usr/local/mysql/var that may be helpful.
The latest information about MySQL is available on the web at
http://www.mysql.com Please consult the MySQL manual section: 'Problems running mysql_install_db',
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/local/mysql/bin/mysqlbug script!
# bin/mysqld_safe --user=mysql & #出現如下提示:
[1] 23095
[root@localhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/var
###這樣就停在這邊,就是正常啟動(dòng)。如果想確認用下面命令
# ps -aux |grep mysql
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
root 23095 0.1 0.2 4408 1084 pts/1 S 04:44 0:00 /bin/sh bin/mysqld_safe --user=mysql
mysql 23118 3.1 2.4 114464 12676 pts/1 Sl 04:44 0:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql --pid-file=/usr/local/mysql/var/localhost.localdomain.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
root 23128 0.0 0.1 5524 640 pts/1 R+ 04:44 0:00 grep mysql
###這樣表示有mysql進(jìn)程
#bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.25-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit
Bye ####只有mysql進(jìn)程,這一步才能執行,因為最初mysql的root密碼是空的,所以回車(chē)直接就進(jìn)入。
#bin/mysqladmin -uroot password 123456 (設置mysql的root密碼為123456)
#[root@Linux mysql]# bin/mysql -u root -p (用新的密碼可以進(jìn)去,表示設置root密碼成功)
Enter password: (輸入完新密碼后變成如下:)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.25-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
#bin/mysqld_safe &或/usr/local/mysql/share/mysql/mysql.server start 啟動(dòng)mysql
#/usr/local/mysql/share/mysql/mysql.server stop 停止mysql
#ps -aux|grep mysql查看進(jìn)程
#kill id號 ----這是殺mysql進(jìn)程的,id號是在查看mysql進(jìn)程里面看的到。
我們來(lái)修改一下mysql的啟動(dòng)的方式,讓它以系統守護進(jìn)程的方式開(kāi)戶(hù)服務(wù)
#cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld 這樣下次就可以用/etc/init.d/mysqld start啟動(dòng)了
# bin/mysql -uroot -p
Enter password:
ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
這個(gè)是mysql沒(méi)啟動(dòng)
# /etc/init.d/mysqld start (或/usr/local/mysql/mysql/share/mysql.server start這樣啟動(dòng))
# bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.0.25-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)
mysql>
#chkconfig --add mysqld 添加mysql為服務(wù)
#chkconfig --del mysqld 刪除mysql服務(wù)
service mysqld restart #重新啟動(dòng)服務(wù)查看是否生效
chkconfig --list mysqld #查看是否345運行級別都打開(kāi)mysql
完成!以上安裝過(guò)程同樣適用于mysql5的安裝
筆者發(fā)現mysql5版本在安裝后即可直接使用mysql命令進(jìn)入數據庫,而在4版本系列中,mysql路徑并沒(méi)有放入系統環(huán)境變量中,輸入mysql系統會(huì )報找不到這命令的錯誤,因此筆者擅自修改了環(huán)境變量,把mysql的路徑添加進(jìn)環(huán)境變量中去。
修改profile文件,將mysql的路徑添加到PATH變量中去。
vi /etc/profile
if ! echo $PATH | /bin/egrep -q "(^|: )$1($|: )" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH: $1:/usr/local/mysql/bin
else
PATH=$1: $PATH:/usr/local/mysql/bin
或
編輯/etc/profile文件:
vi /etc/profile
在文件最后添加如下兩行:
PATH=$PATH:/usr/local/mysql/bin
export PATH
執行下面的命令使所做的更改生效:
. /etc/profile