-
下載MySQL 5.6
-
安裝準備:安裝MySQL依賴函數庫
-
安裝與運行MySQL
-
優化MySQL
(1)賬戶安全優化
(2)數據庫安全優化
1
2
|
xpleaf@leaf:~$ ls mysql* mysql-5.6.28-linux-glibc2.5-x86_64. tar .gz |
1
2
|
xpleaf@leaf:~$ sudo apt-cache search libaio #查找libaio的相關信息 xpleaf@leaf:~$ sudo apt-get install libaio1 #安裝libaio1 |
1
2
|
xpleaf@leaf:~$ sudo groupadd mysql xpleaf@leaf:~$ sudo useradd -r -g mysql -s /bin/false mysql |
1
2
3
|
[root@leaf ~] # cd /usr/local xpleaf@leaf: /usr/local $ sudo tar zxvf /home/xpleaf/mysql-5 .6.28-linux-glibc2.5-x86_64. tar .gz xpleaf@leaf: /usr/local $ sudo ln -s /usr/local/mysql-5 .6.28-linux-glibc2.5-x86_64/ mysql |
1
2
3
|
xpleaf@leaf: /usr/local $ cd mysql xpleaf@leaf: /usr/local/mysql $ ls -d data/ data/ |
1
2
3
4
5
6
7
8
9
10
|
#修改mysql目錄下的所有文件的屬主爲mysql xpleaf@leaf: /usr/local/mysql $ sudo chown -R mysql . #修改mysql目錄下的所有文件的屬組爲mysql xpleaf@leaf: /usr/local/mysql $ sudo chgrp -R mysql . #以mysql用戶的身份初始化數據 xpleaf@leaf: /usr/local/mysql $ sudo scripts /mysql_install_db --user=mysql #修改mysql目錄下的所有文件的屬主爲root xpleaf@leaf: /usr/local/mysql $ sudo chown -R root . #修改mysql目錄下的data目錄的屬主爲mysql xpleaf@leaf: /usr/local/mysql $ sudo chown -R mysql data |
1
2
3
4
|
xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqld_safe --user=mysql & [1] 8365 xpleaf@leaf: /usr/local/mysql $ 160308 14:13:26 mysqld_safe Logging to '/usr/local/mysql-5.6.28-linux-glibc2.5-x86_64/data/leaf.err' . 160308 14:13:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5 .6.28-linux-glibc2.5-x86_64 /data |
1
2
|
xpleaf@leaf:~$ sudo netstat -antup | grep mysqld tcp6 0 0 :::3306 :::* LISTEN 8455 /mysqld |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqladmin version bin /mysqladmin Ver 8.42 Distrib 5.6.28, for linux-glibc2.5 on x86_64 Copyright (c) 2000, 2015, 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 version 5.6.28 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql .sock Uptime: 8 min 36 sec Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.003 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#通過mysqladmin關閉mysql服務 xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqladmin -u root shutdown #啓動mysql服務 xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqld_safe --user=mysql & #查看mysql數據庫中默認存在的數據庫 xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqlshow +--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ #查看mysql數據庫(注意此mysql數據庫是一個實體,與上面的統稱不同)中的數據表 xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqlshow mysql Database: mysql +---------------------------+ | Tables | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | servers | | slave_master_info | | slave_relay_log_info | | slave_worker_info | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ #查看mysql數據庫中的所有user表 xpleaf@leaf: /usr/local/mysql $ sudo bin /mysql -e "SELECT User, Host, plugin FROM mysql.user" mysql +------+-----------+-----------------------+ | User | Host | plugin | +------+-----------+-----------------------+ | root | localhost | mysql_native_password | | root | leaf | mysql_native_password | | root | 127.0.0.1 | mysql_native_password | | root | ::1 | mysql_native_password | | | localhost | mysql_native_password | | | leaf | mysql_native_password | +------+-----------+-----------------------+ |
1
|
xpleaf@leaf:~$ sudo apt-get install mysql-client-core-5.6 |
1
2
|
xpleaf@leaf:~$ mysql ERROR 2002 (HY000): Can 't connect to local MySQL server through socket ' /var/run/mysqld/mysqld .sock' (13) |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
xpleaf@leaf:~$ sudo mkdir /var/run/mysqld xpleaf@leaf:~$ cd /var/run/mysqld/ xpleaf@leaf: /var/run/mysqld $ sudo touch mysqld.sock xpleaf@leaf: /var/run/mysqld $ sudo chown -R mysql:mysql /var/run/mysqld/ xpleaf@leaf: /var/run/mysqld $ cd xpleaf@leaf:~$ sudo bash root@leaf:~ # cd /usr/local/mysql root@leaf: /usr/local/mysql # exit xpleaf@leaf:~$ sudo bash root@leaf:~ # cd /usr/local/mysql root@leaf: /usr/local/mysql # echo socket=/var/run/msqld/mysqld.sock>>my.cnf root@leaf: /usr/local/mysql # exit xpleaf@leaf:~$ sudo ln -s /var/lib/mysql/mysql .sock /tmp/mysql .sock |
1
2
|
xpleaf@leaf:~$ cd /usr/local/mysql xpleaf@leaf: /usr/local/mysql $ sudo bin /mysqld_safe --user=mysql & |
1
2
3
4
5
|
xpleaf@leaf: /usr/local/mysql $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. …… mysql> |
1
2
3
4
5
6
7
8
9
10
11
12
|
mysql> select User, Host, Password from mysql.user; +------+-----------+----------+ | User | Host | Password | +------+-----------+----------+ | root | localhost | | | root | leaf | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | leaf | | +------+-----------+----------+ 6 rows in set (0.00 sec) |
-
使用set password語句
-
使用update語句
-
使用mysqladmin命令
1
2
3
4
5
6
7
|
xpleaf@leaf:~$ mysql -u root -p Enter password: mysql> set password for 'root' @ 'localhost' = password( '123456' ); mysql> set password for 'root' @ '127.0.0.1' = password( '123456' ); mysql> set password for 'root' @ '::1' = password( '123456' ); mysql> set password for 'root' @ 'leaf' = password( '123456' ); mysql> flush privileges; |
1
2
3
4
5
|
xpleaf@leaf:~$ mysql -u root -p Enter password: mysql> update mysql.user set password = password( '123456' ) -> where User = 'root' ; mysql> flush privileges; |
1
2
3
4
|
xpleaf@leaf:~$ mysql -u root ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO) xpleaf@leaf: /usr/local/mysql $ mysql -u root -p Enter password: |
1
2
3
4
5
6
7
8
9
10
11
|
mysql> select User, Host, Password from mysql.user; +------+-----------+-------------------------------------------+ | User | Host | Password | +------+-----------+-------------------------------------------+ | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | leaf | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | ::1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | | localhost | | | | leaf | | +------+-----------+-------------------------------------------+ 6 rows in set (0.00 sec) |
1
2
3
4
|
xpleaf@leaf:~$ mysql -u root -p Enter password: mysql> update mysql.user set password = password( '123456' ) where User = '' ; mysql> flush privileges; |
1
2
3
4
5
|
shell> mysql -u root -p Enter password: (enter root password here) mysql> DROP USER '' @ 'localhost' ; mysql> DROP USER '' @ 'host_name' ; mysql> flush privileges; |
1
2
3
4
|
xpleaf@leaf:~$ mysql -u root -p mysql> delete from mysql.db where db like 'test%' ; mysql> drop database test ; mysql> flush privileges; |