[root@www.solgle.com var]# mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial)
Copyright (c) 2000, 2014, 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> 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
mysql> SET PASSWORD FOR root=password('111111');
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@www.solgle.com var]#
方法二:
mysql> 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
mysql> update user set password=password('111111') where user='root';
Query OK, 0 rows affected (0.03 sec)
Rows matched: 4 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[root@www.solgle.com var]#
方法三:
1:更改root之前有密码的情况
[root@www.solgle.com var]# mysqladmin -u root -p222222 password "111111";
Warning: Using a password on the command line interface can be insecure.
[root@www.solgle.com var]#
2:更改之前root还没有密码
###[root@www.solgle.com var]# mysqladmin -u root -p111111 password "";
###Warning: Using a password on the command line interface can be insecure.
[root@www.solgle.com var]# mysqladmin -u root password "222222";
Warning: Using a password on the command line interface can be insecure.
[root@www.solgle.com var]#
创建一个用户test,对数据库solgle-db有权限
mysql> grant all on solgle-db.* to test identified by "111111";
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
---测试该用户
[root@www.solgle.com var]# mysql -u test -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial)
Copyright (c) 2000, 2014, 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 count(1) from user;
ERROR 1046 (3D000): No database selected
mysql> use mysql
ERROR 1044 (42000): Access denied for user 'test'@'%' to database 'mysql'
mysql> use solgle-db
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
mysql> select count(1) from user;
ERROR 1146 (42S02): Table 'solgle-db.user' doesn't exist
mysql> select count(1) from users;
ERROR 1146 (42S02): Table 'solgle-db.users' doesn't exist
mysql> select count(1) from Users;
+----------+
| count(1) |
+----------+
| 3 |
+----------+
1 row in set (0.01 sec)
mysql>
--从上面可以看出表名是要区分大小写的