#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指定安裝目錄,讓他支持中文,支持全部語
#指定安裝路徑爲/usr/local/mysql,配置文件存放目錄/etc,數據庫存儲目錄/var/lib/mysql
./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql
(供參考)
#make
#make install
#make clean
#groupadd mysql
#useradd -g mysql mysql (第一個mysql是組,第二個mysql是用戶)
#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 網絡上是寫括號內的,但我試了不行#根據本身主機的狀況複製my-*.cnf的一個,huge是應用於內存在2G以上的狀況.)
#bin/mysql_install_db --user=mysql #創建基本數據庫,必須指明爲mysql用戶,只有這一步才能在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
###這樣就停在這邊,就是正常啓動。若是想確認用下面命令
# 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進程
#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進程,這一步才能執行,由於最初mysql的root密碼是空的,因此回車直接就進入。
#bin/mysqladmin -uroot password 123456 (設置mysql的root密碼爲123456)
#[root@Linux mysql]# bin/mysql -u root -p (用新的密碼能夠進去,表示設置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 啓動mysql
#/usr/local/mysql/share/mysql/mysql.server stop 中止mysql
#ps -aux|grep mysql查看進程
#kill id號 ----這是殺mysql進程的,id號是在查看mysql進程裏面看的到。
咱們來修改一下mysql的啓動的方式,讓它以系統守護進程的方式開戶服務
#cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld 這樣下次就能夠用/etc/init.d/mysqld start啓動了
# bin/mysql -uroot -p
Enter password:
ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
這個是mysql沒啓動
# /etc/init.d/mysqld start (或/usr/local/mysql/mysql/share/mysql.server start這樣啓動)
# 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爲服務
#chkconfig --del mysqld 刪除mysql服務
service mysqld restart #從新啓動服務查看是否生效
chkconfig --list mysqld #查看是否345運行級別都打開mysql
完成!以上安裝過程一樣適用於mysql5的安裝
筆者發現mysql5版本在安裝後便可直接使用mysql命令進入數據庫,而在4版本系列中,mysql路徑並無放入系統環境變量中,輸入mysql系統會報找不到這命令的錯誤,所以筆者擅自修改了環境變量,把mysql的路徑添加進環境變量中去。
修改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