[root@server www]# mysql -uroot -p //登录数据库 默认密码应该是root或空 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
[root@server www]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed MariaDB [mysql]> create user 'adminDB'@'%' identified by 'root'; //设置用户名和密码root Query OK, 0 rows affected (0.00 sec)
[root@server www]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show grants for'adminDB'@'%'; +----------------------------------------------------------------------------------------------------------------+ | Grants for adminDB@% | +----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'adminDB'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' | +----------------------------------------------------------------------------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> grant select,insert,update,delete,create,drop on newstaff.* to 'adminDB'@'%'; //只允许adminDB操作数据库newstaff Query OK, 0 rows affected (0.01 sec)
[root@webserver webserver]# mysql -uadminDB -p -P8800 -h 192.168.1.10 //带端口登录 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> use newstaff; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
[root@server /]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show grants for'adminDB'@'%'; +--------------------------------------------------------------------------------------------------------------------+ | Grants for adminDB@% | +--------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'adminDB'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON `newstaff`.* TO 'adminDB'@'%' | +--------------------------------------------------------------------------------------------------------------------+ 2 rows inset (0.00 sec)