因爲Ubuntu Server上 wget比較慢,所以我是直接在windows用迅雷下載好,然後WinSCP上傳到服務器的,看各自喜好了。
上正題。
包放在~/Download目錄下,全部安裝命令如下:
1、解壓tar.gz
tar –xzf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
2、重命名解壓的文件夾
mv mysql-5.6.10-linux-glibc2.5-x86_64 mysql
3、將mysql文件夾移動到/usr/local目錄下
sudo mv ~/下載/mysql /usr/local
4、進入mysql目錄
cd /usr/local/mysql
5、增加mysql用戶組
sudo groupadd mysql
6、增加mysql用戶
sudo useradd -r -g mysql mysql
7、將mysql文件夾own及grp變更爲mysql
sudo chown -R mysql .
sudo chgrp -R mysql .
8、執行mysql安裝腳本
sudo scripts/mysql_install_db --user=mysql
(若未安裝libaio包,會有一個報錯提示,安裝libaio-dev後,再運行腳本即可。如果還是出錯可以刪除rm -rf /etc/my.cnf)
sudo apt-get install libaio-dev
9、將目錄權限變更回來,僅保留data目錄爲mysql用戶
sudo chown -R root .
sudo chown -R mysql data
10、將mysql配置文件拷貝到etc目錄(全局配置)
注意:5.6版本的默認配置文件名稱由原先的my-medium變更爲了my-default。
sudo cp support-files/my-default.cnf /etc/my.cnf
11、啓動mysql
sudo bin/mysqld_safe --user=mysql &
12、初始化mysql root用戶密碼
sudo bin/mysqladmin -u root password '密碼文字'
#ps -A|grep mysql
顯示類似:
1829 ? 00:00:00 mysqld_safe
1876 ? 00:00:31 mysqld
2.#kill -9 1829
3.#kill -9 1876
13、複製mysql.server腳本到/etc/init.d(初始化服務,有些人喜歡改成mysqld,在這裏改就可以)
sudo cp support-files/mysql.server /etc/init.d/mysql.server
14、查看mysql運行狀態
sudo service mysql.server status
如果運行正常,會顯示 MySQL running。
如果顯示 not running,應該是前面沒有啓動服務,可直接用service mysql.server start啓動
sudo service mysql.server [status|start|stop]
15、讓mysql開機啓動[defaults],取消開機啓動[remove]
sudo update-rc.d -f mysql.server defaults [remove]
16、將mysql/bin/mysql命令加入到用戶命令中,或將mysql/bin目錄加入path
加入用戶命令:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
加入環境變量:
export PATH=$PATH:/usr/local/mysql/bin
17、允許root用戶遠程登錄
1>進入mysql: mysql –u root –p
2>改變數據庫: use mysql;
3>從任意主機登錄: grant all privileges on *.* to root@"%" identified by "密碼文字" with grant option;
4>從指定主機登錄: grant all privileges on *.* to root@"192.168.1.101" identified by "passw0rd" with grant option;
5>授權生效: flush privileges;
6>查看host爲%授權是否添加: select * from user;
7>查看數據庫字符集: show variables like 'character%';
啓動完mysql後,我們接着可以測試一下,使用“mysql”命令來進入mysql數據庫的控制檯
$mysql -u root
在這裏之所以用-u root是因爲我現在是一般用戶(firehare),如果不加-u root的話,mysql會以爲是firehare在登錄。注意,我在這裏沒有進入根用戶模式,因爲沒必要。一般來說,對mysql中的數據庫進行操作,根本沒必要進入根用戶模式,只有在設置時纔有這種可能。
進入mysql之後,最要緊的就是要設置Mysql中的root用戶密碼了,否則,Mysql服務無安全可言了。
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
如果需要使用root從其他機器遠程訪問可以使用
mysql> GRANT ALL PRIVILEGES ON *.* TO root@“%” IDENTIFIED BY "123456";
注意,我這兒用的是123456做爲root用戶的密碼,但是該密碼是不安全的,請大家最好使用大小寫字母與數字混合的密碼,且不少於8位。
配置文件參考:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
character_set_server=utf8
lower_case_table_names=1
init_connect='SET NAMES utf8'
lower_case_table_names=1
max_connections=3000
max_allowed_packet = 32M
thread_cache_size = 16
thread_concurrency = 8
query_cache_size = 128M
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 16M
sort_buffer_size = 16M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
quote-names
max_allowed_packet = 32M
[mysql]
no-auto-rehash
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
character_set_server=utf8
lower_case_table_names=1
init_connect='SET NAMES utf8'
lower_case_table_names=1
max_connections=3000
max_allowed_packet = 32M
thread_cache_size = 16
thread_concurrency = 8
query_cache_size = 128M
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 16M
sort_buffer_size = 16M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
quote-names
max_allowed_packet = 32M
[mysql]
no-auto-rehash