既有環境:html
1)下載MySQL Community Server 5.6.17 壓縮版(mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz)mysql
2)安裝目錄: /opt/library/mysql-5.6.17-linux-glibc2.5-x86_64linux
3)軟連接爲/opt/library/mysql,指向同目錄下的mysql-5.6.17-linux-glibc2.5-x86_64sql
1. 建立mysql專有的用戶和組bash
$ sudo groupadd mysql $ sudo useradd -r -g mysql mysql
2. 修改mysql文件夾及軟連接的ownersocket
$ sudo chown -R mysql:mysql mysql-5.6.17-linux-glibc2.5-x86_64/ $ sudo chown -R mysql:mysql mysql
3. 使用mysql_install_db初始化受權表。此操做只是在MySQL初次安裝時才須要執行,若是是已存在的安裝,則能夠跳過此步驟,不然會覆蓋先前的受權信息。ui
$ sudo scripts/mysql_install_db --user=mysql
4. 發現mysql_install_db執行有錯誤。看錯誤提示,原來是由於缺乏共享庫libaio1。spa
xuyuzhu@xuyuzhu-OptiPlex-990:/opt/library/mysql$ sudo scripts/mysql_install_db --user=mysql Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
5. 安裝libaio1server
$ sudo apt-get install libaio1
6. 從新執行第三步,如下是幾行關鍵loghtm
Installing MySQL system tables...2014-05-15 14:43:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). . . 建立第一張數據表、表大小、buffer、fk、log文件 . Filling help tables...2014-05-15 14:43:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). . . 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: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h xuyuzhu-OptiPlex-990 password 'new-password' Alternatively you can run: ./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 . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl . .
總結下:
1)support-files/mysql.server用於啓動mysql
2)可用 mysqladmin 或 mysql_secure_installation 命令修改密碼
3)能夠使用"cd . ; ./bin/mysqld_safe &"配置mysql守護進程
7. 添加mysql啓動腳本軟連接
$ cd /etc/init.d/ $ sudo ln -s /opt/library/mysql/support-files/mysql.server
8. 啓動mysql服務
xuyuzhu@xuyuzhu-OptiPlex-990:/etc/init.d$ ./mysql.server start /etc/init.d/mysql.server: 1: /etc/init.d/mysql.server: my_print_defaults: not found /etc/init.d/mysql.server: 276: cd: can't cd to /usr/local/mysql Starting MySQL * Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
9. 報錯。由於mysql.server裏讀取mysql的目錄是/user/local/mysql,因此在/user/local/中建立一個,mysql的軟連接到/opt/library/mysql。再執行第8步。
$ ln -s /opt/library/mysql /usr/local/mysql $ sudo chown mysql:mysql /usr/local/mysql $ sudo ./mysql.server start # 上面必須使用sudo權限啓動, 否則會報 . * The server quit without updating PID file (/usr/local/mysql/data/xuyuzhu-OptiPlex-990.pid). Starting MySQL
10. ps檢查進程
xuyuzhu@xuyuzhu-OptiPlex-990:/etc/init.d$ ps -aux |grep mysql root 373 0.0 0.0 4444 744 pts/13 S 15:16 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/xuyuzhu-OptiPlex-990.pid mysql 484 2.4 11.4 976004 448164 pts/13 Sl 15:16 0:00 /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/xuyuzhu-OptiPlex-990.err --pid-file=/usr/local/mysql/data/xuyuzhu-OptiPlex-990.pid xuyuzhu 511 0.0 0.0 15960 916 pts/13 S+ 15:16 0:00 grep --color=auto mysql
11. mysqladmin檢查是否能夠使用mysql
$ mysqladmin version mysqladmin Ver 8.42 Distrib 5.6.17, for linux-glibc2.5 on x86_64 Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version5.6.17 Protocol version10 ConnectionLocalhost via UNIX socket UNIX socket/tmp/mysql.sock Uptime:4 min 48 sec Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.006
12. 添加開機啓動mysql服務守護進程
xuyuzhu@xuyuzhu-OptiPlex-990:/etc/init.d$ sudo update-rc.d mysql.server defaults Adding system startup for /etc/init.d/mysql.server ... /etc/rc0.d/K20mysql.server -> ../init.d/mysql.server /etc/rc1.d/K20mysql.server -> ../init.d/mysql.server /etc/rc6.d/K20mysql.server -> ../init.d/mysql.server /etc/rc2.d/S20mysql.server -> ../init.d/mysql.server /etc/rc3.d/S20mysql.server -> ../init.d/mysql.server /etc/rc4.d/S20mysql.server -> ../init.d/mysql.server /etc/rc5.d/S20mysql.server -> ../init.d/mysql.server
13. that’s all.
參考http://www.cnblogs.com/eastson/archive/2012/06/09/2543489.html
ps. Redhat啓動mysql服務: /etc/init.d/mysqld start