1、查看數(shù)據(jù)庫的版本信息:
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供柏鄉(xiāng)網(wǎng)站建設(shè)、柏鄉(xiāng)做網(wǎng)站、柏鄉(xiāng)網(wǎng)站設(shè)計(jì)、柏鄉(xiāng)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、柏鄉(xiāng)企業(yè)網(wǎng)站模板建站服務(wù),十余年柏鄉(xiāng)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
MariaDB [(none)]> select version(); +----------------+ | version() | +----------------+ | 5.5.52-MariaDB | +----------------+ 1 row in set (0.18 sec)
2、刪除多余的賬號(hào)(除root和localhost的)
MariaDB [(none)]> use MySQL MariaDB [mysql]> select user,host from mysql.user; +------+------------------------+ | user | host | +------+------------------------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | lvs-dr01.saltstack.com | | root | lvs-dr01.saltstack.com | +------+------------------------+ 6 rows in set (0.03 sec) MariaDB [mysql]> delete from mysql.user where (user,host) not in (select 'root','localhost'); Query OK, 5 rows affected (0.05 sec) MariaDB [mysql]> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | localhost | +------+-----------+ 1 row in set (0.05 sec)
3、修改mysql默認(rèn)的mysql管理賬號(hào)
修改默認(rèn)的mysql管理賬號(hào)(root改為mysql,并設(shè)置新密碼為redhat12345)
MariaDB [mysql]> update user set user="admin" where user="root"; MariaDB [mysql]> update mysql.user set user='admin',password=password('redhat12345'); Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.03 sec) [root@LVS-DR01 ~]# mysql -uadmin -p'redhat12345' MariaDB [(none)]> user mysql; MariaDB [mysql]> show tables;
繼續(xù)查詢:
MariaDB [mysql]> select user,host from mysql.user; +-------+-----------+ | user | host | +-------+-----------+ | admin | localhost | +-------+-----------+ 1 row in set (0.00 sec)
4、刪除test數(shù)據(jù)庫:
MariaDB [mysql]> drop database test; MariaDB [mysql]> flush privileges; MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.06 sec)
5、優(yōu)化權(quán)限字典表mysql.db
如下所示:新建MySQL數(shù)據(jù)庫后,默認(rèn)創(chuàng)建的test數(shù)據(jù)庫權(quán)限比較怪異,所有可連接的用戶都能夠擁有權(quán)限訪問該庫,并操作其中的對(duì)象,Host為%,User為空,說明了不受限制,所有能連接到MySQL的用戶,全部擁有test及test開頭的數(shù)據(jù)庫的幾乎所有權(quán)限。
MariaDB [mysql]> select * from mysql.db where db like 'test%' \G *************************** 1. row *************************** Host: % Db: test User: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Grant_priv: N References_priv: Y Index_priv: Y Alter_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: N Execute_priv: N Event_priv: Y Trigger_priv: Y *************************** 2. row *************************** Host: % Db: test\_% User: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Grant_priv: N References_priv: Y Index_priv: Y Alter_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: N Execute_priv: N Event_priv: Y Trigger_priv: Y 2 rows in set (0.31 sec) 優(yōu)化的操作: MariaDB [mysql]> truncate table mysql.db; Query OK, 0 rows affected (0.01 sec) MariaDB [mysql]> select * from mysql.db where db like 'test%' \G Empty set (0.00 sec)
6、如何優(yōu)化/root/.mysql_history文件
[root@LVS-DR01 ~]# tail -20 ~/.mysql_history flush privileges; select user,host from mysql.user; delete from mysql.user where user="'molewan1'@'10.10.10.%'"; delete from mysql.db where user='molewan1'@'10.10.10.%'; select user,host from mysql.user; delete from mysql.user where user=molewan1; delete from mysql.user where user='molewan1@10.10.10.%'; flush privileges; select user,host from mysql.user; delete from mysql.user where user="molewan1" and host ="10.10.10.%"; flush privileges; select user,host from mysql.user; delete from mysql.user where user="molewan" and host="10.10.10.%"; flush privileges; create user molewan@'10.10.10.%' identified by 'molewan'; select user,host from mysql.user; desc mysql.user; update mysql.user set password=password('admin') where user='admin' and host='localhost'; flush privileges; \q
說明:在Linux/Unix系統(tǒng)下,使用mysql命令行工具執(zhí)行的所有操作,都會(huì)被記錄到一個(gè)名為.mysql_history的文件中,該文件默認(rèn)保存在當(dāng)前用戶的根目錄下
這個(gè)設(shè)定原本是為了提升mysql命令行操作體驗(yàn),在mysql中操作命令就可以上下翻動(dòng)了,但某些情況下缺會(huì)造成隱患。
如何消除隱患:
方法1:基于DB層的操作 修改MYSQL_HISTFILE環(huán)境變量,將其值改為/dev/null,這樣所有的操作都會(huì)被輸出到空,操作的歷史 自然不會(huì)被保留。 方法2:基于系統(tǒng)層操作 仍舊保留這個(gè)文件,但是改文件實(shí)際上未/dev/null的軟鏈接,這樣所有的操作都會(huì)被輸出到空,操作的歷史自然不會(huì)被保留。 ln -f -s /dev/null ~/.mysql_history [root@LVS-DR01 ~]# tail -20 ~/.mysql_history 這時(shí)候就沒有輸出了
到此,安裝完成后的基本優(yōu)化已經(jīng)完成