[root@linuxidc mysql]# pwd /usr/local/mysql [root@linuxidc mysql]# bin/mysqladmin version bin/mysqladmin Ver 8.42 Distrib 5.6.28, for Linux 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: 9 min 7 sec Threads: 1 Questions: 9 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.016 [root@linuxidc mysql]#
[root@linuxidc mysql]# bin/mysqladmin variables +--------------------------------------------------------+----------------------------------------------------------------------------------+ | Variable_name | Value | +--------------------------------------------------------+----------------------------------------------------------------------------------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | avoid_temporal_upgrade | OFF | | back_log | 80 | | basedir | /usr/local/mysql | …… | +--------------------------------------------------------+----------------------------------------------------------------------------------+ [root@linuxidc mysql]#
设置 MySQL 访问权限第十一步:设置访问权限。
使用 mysql_install_db 安装 MySQL 数据库授权表,定义了初始 MySQL 用户账号和访问权限,所有账号均没有密码。这些账号为超级用户,可以执行任何操作。
初始 root 账户的密码为空,任何人可以用 root 账户不用输入任何密码就可以连接 MySQL 服务器,并具有所有权限,这意味着 MySQL 安装未受保护。所以,应该为匿名账户指定密码或删除匿名账户,为 MySQL root 账户指定密码。使用“mysql –u root”启动 MySQL 客户端控制台,连接 MySQL 服务器。命令行如下。
[root@linuxidc mysql]# cd /usr/local/mysql [root@linuxidc mysql]# bin/mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.6.28 Source distribution 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select now(); +---------------------+ | now() | +---------------------+ | 2016-02-02 08:02:31 | +---------------------+ 1 row in set (0.00 sec) mysql>
第十二步:如果匿名账户存在,并拥有全部权限,因此,删掉它可以提高安全,在 MySQL 客户端执行如下命令。
mysql> select * from mysql.user \G *************************** 1. row *************************** Host: localhost User: root Password: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: password_expired: N *************************** 2. row *************************** Host: linuxidc User: root Password: Select_priv: Y ……: …… *************************** 3. row *************************** Host: 127.0.0.1 User: root Password: Select_priv: Y ……: …… *************************** 4. row *************************** Host: ::1 User: root Password: Select_priv: Y ……: …… *************************** 5. row *************************** Host: localhost User: Password: Select_priv: N Insert_priv: N Update_priv: N Delete_priv: N Create_priv: N Drop_priv: N Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: N Create_tablespace_priv: N ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: NULL password_expired: N *************************** 6. row *************************** Host: linuxidc User: Password: Select_priv: N ……: …… 6 rows in set (0.00 sec) mysql>