您好,登錄后才能下訂單哦!
1、查看數據庫的版本信息:
MariaDB [(none)]> select version(); +----------------+ | version() | +----------------+ | 5.5.52-MariaDB | +----------------+ 1 row in set (0.18 sec)
2、刪除多余的賬號(除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默認的mysql管理賬號
修改默認的mysql管理賬號(root改為mysql,并設置新密碼為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;
繼續查詢:
MariaDB [mysql]> select user,host from mysql.user; +-------+-----------+ | user | host | +-------+-----------+ | admin | localhost | +-------+-----------+ 1 row in set (0.00 sec)
4、刪除test數據庫:
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、優化權限字典表mysql.db
如下所示:新建MySQL數據庫后,默認創建的test數據庫權限比較怪異,所有可連接的用戶都能夠擁有權限訪問該庫,并操作其中的對象,Host為%,User為空,說明了不受限制,所有能連接到MySQL的用戶,全部擁有test及test開頭的數據庫的幾乎所有權限。
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) 優化的操作: 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、如何優化/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系統下,使用mysql命令行工具執行的所有操作,都會被記錄到一個名為.mysql_history的文件中,該文件默認保存在當前用戶的根目錄下
這個設定原本是為了提升mysql命令行操作體驗,在mysql中操作命令就可以上下翻動了,但某些情況下缺會造成隱患。
如何消除隱患:
方法1:基于DB層的操作 修改MYSQL_HISTFILE環境變量,將其值改為/dev/null,這樣所有的操作都會被輸出到空,操作的歷史 自然不會被保留。 方法2:基于系統層操作 仍舊保留這個文件,但是改文件實際上未/dev/null的軟鏈接,這樣所有的操作都會被輸出到空,操作的歷史自然不會被保留。 ln -f -s /dev/null ~/.mysql_history [root@LVS-DR01 ~]# tail -20 ~/.mysql_history 這時候就沒有輸出了
到此,安裝完成后的基本優化已經完成
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。