在http://dev.mysql.com/downloads/mysql/ 官網上下載mysql-5.5.28-linux2.6-i686.tar.gz.html
2. 解壓mysql
假如tar包在/home/zdw/software目錄下linux
#tar -xvf mysql-5.5.28-linux2.6-i686.tar.gzsql
3. 移動到/usr/local/mysqlshell
#mv mysql-5.5.28-linux2.6-i686 /usr/local/數據庫
添加快捷方式mysql指向mysql-5.5.28-linux2.6-i686bash
#ln -s mysql-5.5.28-linux2.6-i686/ mysqlsocket
4. 安裝依賴的lib包:執行/usr/local/mysql/bin/mysqld,報錯post
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory測試
使用apt-cache search libaio,找到以下軟件源
libaio-dev - Linux kernel AIO access library - development files
libaio1 - Linux kernel AIO access library - shared library
libaio1-dbg - Linux kernel AIO access library - debugging symbols
使用#apt-get install libaio1 安裝
5. 配置用戶,目錄
#groupadd mysql
#useradd -r -g mysql mysql
#cd /usr/local/mysql
#chown -R mysql .
#chgrp -R mysql .
6. 初始化mysql
假如當前目錄爲/usr/local/mysql
#scripts/mysql_install_db --user=mysql
7. 啓動mysql
最簡單的啓動方式:
#/usr/local/mysql/bin/mysqld --user=mysql
默認狀況下使用/usr/local/mysql/data做爲mysql的數據目錄,包括數據庫文件,log日誌。
經常使用的mysql啓動參數:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --port=3306 --socket=/tmp/mysql.socks
推薦的啓動mysql
#/usr/local/mysql/support-files/mysql.server start
啓動完成以後用ps -ef |grep mysql 命令查看是否啓動
8. 登陸mysql
#/usr/local/mysql/bin/mysql -u root -p
默認密碼爲空
修改root密碼
mysql>use mysql ;
mysql>update user set password=PASSWORD("123456") where user='root';
mysql>FLUSH PRIVILEGES;
9. 關閉mysql
最簡單的方式
#killall mysqld
推薦的方式
#/usr/local/mysql/support-files/mysql.server stop
使用mysql.server stop關閉mysqld會銷燬pid文件,並作容錯操做,可是最後也是調用kill命令kill mysql。
關閉mysql,儘可能不要用kill -9 mysql_pid或者是killall -9 mysql,不然mysql進程沒法作退出處理,就可能會丟失數據,甚至致使表損壞。
10. 淺析mysql.server腳本的啓動流程
mysql.server腳本能夠看到在如下腳本調用mysqld_safe這個bash
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
默認狀況下,$bindir/mysqld_safe就是/usr/local/mysql/bin/mysqld_safe這個shell,個人本機的調用參數以下:
/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/blue-pc.pid
而mysqld_safe也是一個shell,能夠看到在這個腳本在初始化N多變量後,調用
eval_log_error "$cmd"
這個shell function最後就是調用
#echo "Running mysqld: [$cmd]" eval "$cmd"
在我本機,這個$cmd就是
/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/blue-pc.err --pid-file=/usr/local/mysql/data/blue-pc.pid
參考文章:http://dev.mysql.com/doc/refman/5.5/en/binary-installation.html
本文在Ubuntu11.04和Fedora14下測試成功。
root@zwj-virtual-machine1:/usr/local/mysql-5.5.28-linux2.6-i686# scripts/mysql_install_db --user=mysql
scripts/mysql_install_db: 1: scripts/mysql_install_db: ./bin/my_print_defaults: not found
Neither host 'zwj-virtual-machine1' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
root@zwj-virtual-machine1:/usr/local/mysql-5.5.28-linux2.6-i686# scripts/mysql_install_db --user=mysql --force option
scripts/mysql_install_db: 1: scripts/mysql_install_db: ./bin/my_print_defaults: not found
Installing MySQL system tables...
scripts/mysql_install_db: 403: scripts/mysql_install_db: ./bin/mysqld: not found
Installation of system tables failed! Examine the logs in
./data for more information.
You can try to start the mysqld daemon with:
shell> ./bin/mysqld --skip-grant &
and use the command line tool ./bin/mysql
to connect to the mysql database and look at the grant tables:
shell> ./bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in ./data that may be helpful.
Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.
Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the ./bin/mysqlbug script!
root@zwj-virtual-machine1:/usr/local/mysql-5.5.28-linux2.6-i686#