在CentOS上原始碼安裝MySQL+安裝問題解決+安全優化
-
下載MySQL 5.6
-
安裝準備:安裝MySQL依賴函式庫
-
安裝與執行MySQL
-
優化MySQL
(1)賬戶安全優化
(2)資料庫安全優化
1
2
|
[root@leaf ~] # ls
mysql-5.6.29-linux-glibc2.5-x86_64. tar .gz
|
1
2
3
4
5
6
|
[root@leaf ~] # yum search libaio #查詢libaio的相關資訊
[root@leaf ~] # yum install libaio #安裝libaio
Loaded plugins: security Setting up Install Process Package libaio-0.3.107-10.el6.x86_64 already installed and latest version Nothing to do
|
1
2
|
[root@leaf ~] # groupadd mysql
[root@leaf ~] # useradd -r -g mysql -s /bin/false mysql
|
1
2
3
|
[root@leaf ~] # cd /usr/local
[root@leaf local ] # tar zxvf /root/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
[root@leaf local ] # ln -s /usr/local/mysql-5.6.29-linux-glibc2.5-x86_64/ mysql
|
1
2
3
|
[root@leaf local ] # cd mysql
[root@leaf mysql] # ls -d data/
data/ |
1
2
3
4
5
|
[root@leaf mysql] # chown -R mysql . #修改mysql目錄下的所有檔案的屬主為mysql
[root@leaf mysql] # chgrp -R mysql . #修改mysql目錄下的所有檔案的屬組為mysql
[root@leaf mysql] # scripts/mysql_install_db --user=mysql #以mysql使用者的身份初始化資料
[root@leaf mysql] # chown -R root . #修改mysql目錄下的所有檔案的屬主為root
[root@leaf mysql] # chown -R mysql data #修改mysql目錄下的data目錄的屬主為mysql
|
1
2
3
4
5
|
[root@leaf mysql] # bin/mysqld_safe --user=mysql &
[1] 30877 [root@leaf mysql] # 160306 11:58:50 mysqld_safe Logging to `/var/log/mysqld.log`.
160306 11:58:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160306 11:58:51 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld .pid ended
|
1
2
3
4
5
|
[root@leaf ~] # tail -f /var/log/mysqld.log
...... 2016-03-06 12:00:36 31231 [ERROR] /usr/local/mysql/bin/mysqld : Can `t create/write to file ` /var/run/mysqld/mysqld .pid` (Errcode: 2 - No such file or directory)
2016-03-06 12:00:36 31231 [ERROR] Can `t start server: can` t create PID file : No such file or directory
160306 12:00:36 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld .pid ended
|
1
2
3
4
5
|
[root@leaf mysql] # mkdir /var/run/mysqld
[root@leaf mysql] # cd /var/run/mysqld/
[root@leaf mysqld] # touch mysqld.pid #建立mysqld.pid檔案
[root@leaf mysqld] # cd ..
[root@leaf run] # chown -R mysql mysqld #將mysqld目錄的屬主設定為mysql
|
1
2
3
4
|
[root@leaf run] # cd /usr/local/mysql
[root@leaf mysql] # bin/mysqld_safe --user=mysql
160306 12:12:45 mysqld_safe Logging to `/var/log/mysqld.log` .
160306 12:12:45 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
|
1
2
3
4
|
[root@leaf ~] # netstat -antup
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 31484 /mysqld
|
1
2
3
4
|
[root@leaf mysql] # bin/mysqladmin version
bin /mysqladmin : connect to server at `localhost` failed
error: `Can` t connect to local MySQL server through socket `/tmp/mysql.sock` (2)`
Check that mysqld is running and that the socket: `/tmp/mysql.sock` exists!
|
1
|
[root@leaf mysql] # ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@leaf mysql] # bin/mysqladmin version
bin /mysqladmin Ver 8.42 Distrib 5.6.29, for linux-glibc2.5 on x86_64
Copyright (c) 2000, 2016, 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.29 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql .sock
Uptime: 6 min 36 sec Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.005 |
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
|
[root@leaf mysql] # bin/mysqladmin -u root shutdown #通過mysqladmin關閉mysql服務
[root@leaf mysql] # bin/mysqld_safe --user=mysql & #啟動mysql服務
#檢視mysql資料庫中預設存在的資料庫 [root@leaf mysql] # bin/mysqlshow
+--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | performance_schema | | test |
+--------------------+ #檢視mysql資料庫(注意此mysql資料庫是一個實體,與上面的統稱不同)中的資料表
[root@leaf mysql] # 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表 [root@leaf mysql] # 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
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@leaf ~] # mysql
Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 7
Server version: 5.6.29 MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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. Type `help;` or `h` for help. Type `c` to clear the current input statement.
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
|
[root@leaf ~] # mysql -u root
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
|
[root@leaf ~] # mysql -u root
mysql> update mysql.user set password = password( `123456` )
-> where User = `root` ;
mysql> flush privileges; |
1
|
[root@leaf ~] # mysqladmin -u root password `123456`
|
1
2
3
4
|
[root@leaf ~] # mysql -u root
ERROR 1045 (28000): Access denied for user `root` @ `localhost` (using password: NO)
[root@leaf ~] # 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
|
[root@leaf ~] # mysql -u root -p
Enter password: mysql> update mysql.user set password = password( `123456` ) where User = `` ;
mysql> flush privileges; |
1
2
3
4
|
shell> mysql -u root -p Enter password: (enter root password here) mysql> DROP USER `` @ `localhost` ;
mysql> DROP USER `` @ `host_name` ;
|
1
2
3
4
|
[root@leaf ~] # mysql -u root -p
mysql> delete from mysql.db where db like `test%` ;
mysql> drop database test ;
mysql> flush privileges; |
相關文章
- 在Ubuntu上原始碼安裝MySQL+安裝問題解決+安全優化Ubuntu原始碼MySql優化
- 在CentOS上使用yum安裝MySQL+安全優化CentOSMySql優化
- 在Ubuntu上使用apt-get安裝MySQL+安全優化Ubuntuapt-getMySql優化
- MySQL在CentOS 6.4 原始碼安裝MySqlCentOS原始碼
- 在CentOS上安裝GitCentOSGit
- 在centos上安裝molochCentOS
- 在CentOS上安裝dockerCentOSDocker
- 在CentOS上安裝PowerShellCentOS
- 在Centos上安裝wordpressCentOS
- hive在centos上安裝HiveCentOS
- 原始碼安裝apache(附遇到的問題及解決)原始碼Apache
- Centos原始碼安裝NginxCentOS原始碼Nginx
- 在Linux上安裝Oracle時DISPLAY問題解決方案LinuxOracle
- 在CentOS 8.1上安裝 DockerCentOSDocker
- SonarQube在CentOS上的安裝CentOS
- 在CentOS上安裝GITLABCentOSGitlab
- redis 安裝及安裝遇到的問題解決Redis
- 在CentOS6上使用saltstack原始碼安裝配置mysql薦CentOS原始碼MySql
- 在 Ubuntu 上使用原始碼安裝 OpenRestyUbuntu原始碼REST
- 在Centos7上安裝DockerCentOSDocker
- 在CentOS 7上安裝TensorflowCentOS
- 在Centos6.5上安裝ossfsCentOS
- redis安裝及問題解決Redis
- Centos 7 上安裝 jdk 及問題小記CentOSJDK
- 在Centos和Docker上安裝STF 遇到的若干問題總結CentOSDocker
- 在linux中安裝mysql並解決中文亂碼問題LinuxMySql
- CentOS6.5安裝mysql以及常見問題的解決CentOSMySql
- 在Centos7上安裝圖形化桌面工具CentOS
- CentOS7原始碼安裝NginxCentOS原始碼Nginx
- CentOS 7 原始碼安裝 Zabbix 6.0CentOS原始碼
- centos6.0LAMP原始碼安裝CentOSLAMP原始碼
- Centos7 系統安裝 Oracle 無法調出圖形安裝介面問題解決CentOSOracle
- 安裝 laraBBS 原始碼包可能會碰到的問題及解決方法原始碼
- 在Mac上安裝Windows常見問題MacWindows
- CentOS 上安裝 NginxCentOSNginx
- centos上安裝grafanaCentOSGrafana
- centos上安裝redmineCentOS
- pgsql優勢,pgsql安裝(centOs),pgagent安裝SQLCentOS