关于MySQL的多用户问题

来源:互联网 发布:阿里云 马云 王坚 编辑:程序博客网 时间:2024/05/21 14:04

1)进入控制台

   方法一:通过安装的MySQL Commond Line Client输入密码进入控制台

   方法二:通过Dos命令提示符进入

1. 找到MySQL的安装目录下的bin文件夹,复制路径。

2. 在命令提示行中使用cd命令,切换到MySQLbin目录

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Windows\system32>cd../../

C:\>cd C:\Program Files\MySQL\MySQL Server 5.6\bin

2)登陆

1、输入登陆的命令:mysql -h 主机名 -u 用户名 -p 

2、系统提示输入密码

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -h localhost -u root -p
Enter password: ***

3、登陆成功
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.13-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial)

Copyright (c) 2000, 2013, 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.

3)创建数据库

使用root用户创建数据

mysql> create database zhuyanli;
Query OK, 1 row affected (0.34 sec)

4)添加用户:

使用root用户添加其他用户

1、添加用户

mysql> insert into mysql.user(host,user,password,ssl_cipher,x509_issuer,x509_sub
ject,authentication_string)values('localhost','zhuyanli',password('123'),'y','y'
,'y','y');
Query OK, 1 row affected (0.53 sec)

1、给用户授权

mysql> grant all privileges on zhuyanli.* to lijiantao identified by"123";
Query OK, 0 rows affected (0.20 sec)

5用新添加的用户登陆

mysql> \q
Bye

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -h lijiantao -u zhuyanli -p
Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 45
Server version: 5.6.13-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial)

Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| student |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql> \q
Bye

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -h 172.22.64.26 -u lijiantao -
p
Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.6.13-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial)

Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| student |
| test |
+--------------------+
3 rows in set (0.00 sec)