一.下載mysql-5.1.45.tar.gz
http://dev.mysql.com/downloads
或其它地方下載
二.添加mysql用戶及mysql用戶組,并把mysql用戶放到mysql用戶組中
useradd mysql
等與用下面兩條命令:
groupadd mysql
useradd -g mysql mysql
三.上傳到/usr/local/src下(方便管理)解壓安裝
[root@localhost src]# tar -zxvf mysql-5.1.45.tar.gz
[root@localhost src]# cd mysql-5.1.45
1.編譯
[root@localhost mysql-5.1.45]# ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-named-curses-libs=/usr/lib/libncurses.so.5
2.安裝
[root@localhost mysql-5.1.45]# make && make install (這個時間比較長)
3.將mysql加入到系統變量path中
將/usr/local/mysql/bin 加入到path中,這樣在shell里就可以運行mysql相關的命令。
[root@localhost mysql-5.1.45]# vi /etc/profile
加入
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
如果同時安裝tomcat可以采用下面的方式
export TOMCAT_HOME=/home/coomix/apache-tomcat-5.5.27
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:TOMCAT_HOME/bin:$PATH
[root@localhost mysql-5.1.45]# source /etc/profile 使配置文件立即生效
4.進入到mysql文件夾下,初始化mysql表格,安裝 mysql 默認數據庫
[root@localhost mysql-5.1.45]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin docs include lib libexec mysql-test share sql-bench
[root@localhost mysql]# mysql_install_db --user=mysql
5.修改目錄權限
[root@localhost mysql]# chown -R root:mysql .
[root@localhost mysql]# chown -R mysql var
[root@localhost mysql]# chgrp -R mysql .
6.修改配置,將mysql加入系統服務:
[root@localhost mysql]# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost mysql]# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
7.啟動mysql
[root@localhost mysql]# service mysqld
Usage: /etc/init.d/mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
[root@localhost mysql]# service mysqld start
Starting MySQL. [確定]
[root@localhost mysql]#
8.使用mysql,默認root用戶是沒有密碼的
[root@localhost mysql]# cd bin
[root@localhost bin]# ./mysql -u root -p
Enter password: 直接按回車
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.45-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9.修改root密碼
[root@localhost bin]# mysqladmin -u root password 'root'
[root@localhost bin]# mysqladmin -u root -h host_name password 'root'
mysqladmin: connect to server at 'host_name' failed
error: 'Unknown MySQL server host 'host_name' (1)'
Check that mysqld is running on host_name and that the port is 3306.
You can check this by doing 'telnet host_name 3306'
[root@localhost bin]# ./mysql -u root -p
Enter password: 輸入root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
mysql> quit
Bye
[root@localhost bin]#
附:[root@localhost mysql]# mysql_install_db --user=mysql執行后的顯示:
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/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql/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/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl