十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
[root@gary-tao ~]# mysql -uroot -p'szyino-123'
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> grant all on *.* to 'user1'@'127.0.0.1' identified by 'szyino-123'; //创建一个普通用户并授权
Query OK, 0 rows affected (0.00 sec)
[root@gary-tao ~]# mysql -uuser1 -pszyino-123 //由于指定IP,报错不能登录
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'user1'@'localhost' (using password: YES)
[root@gary-tao ~]# mysql -uuser1 -pszyino-123 -h227.0.0.1 //加-h指定IP登录,正常
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
mysql> grant all on *.* to 'user1'@'localhost' identified by 'szyino-123'; //授权localhost,所以该用户默认使用(监听)本地mysql.socket文件,不需要指定IP即可登录
Query OK, 0 rows affected (0.00 sec)
mysql> ^DBye
[root@gary-tao ~]# mysql -uuser1 -pszyino-123 //正常登录
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*B1E761CAD4A61F6FD6B02848B5973BC05DE1C315' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for user1@'127.0.0.1';
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for user1@127.0.0.1 |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'user1'@'127.0.0.1' IDENTIFIED BY PASSWORD '*B1E761CAD4A61F6FD6B02848B5973BC05DE1C315' |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
第一种形式:
创新互联,是成都地区的互联网解决方案提供商,用心服务为企业提供网站建设、成都app软件开发公司、小程序制作、系统按需求定制开发和微信代运营服务。经过数十载的沉淀与积累,沉淀的是技术和服务,让客户少走弯路,踏实做事,诚实做人,用情服务,致力做一个负责任、受尊敬的企业。对客户负责,就是对自己负责,对企业负责。
mysql> use db1;
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(*) from mysql.user;
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.00 sec)
//注释:mysql.user表示mysql的user表,count(*)表示表中共有多少行。
第二种形式:
mysql> select * from mysql.db;
//它表示查询mysql库的db表中的所有数据
mysql> select db from mysql.db;
+---------+
| db |
+---------+
| test |
| test\_% |
+---------+
2 rows in set (0.00 sec)
//查询db表里的db单个字段
mysql> select db,user from mysql.db;
+---------+------+
| db | user |
+---------+------+
| test | |
| test\_% | |
+---------+------+
2 rows in set (0.00 sec)
//查看db表里的db,user多个字段
mysql> select * from mysql.db where host like '192.168.%'\G;
//查询db表里关于192.168.段的ip信息
mysql> desc db1.t1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(4) | YES | | NULL | |
| name | char(40) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from db1.t1;
Empty set (0.00 sec)
mysql> insert into db1.t1 values (1, 'abc'); //插入一行数据
Query OK, 1 row affected (0.01 sec)
mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
+------+------+
1 row in set (0.00 sec)
mysql> insert into db1.t1 values (1, '234');
Query OK, 1 row affected (0.00 sec)
mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 1 | 234 |
+------+------+
2 rows in set (0.00 sec)
mysql> update db1.t1 set name='aaa' where id=1;
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | aaa |
| 1 | aaa |
+------+------+
2 rows in set (0.00 sec)
mysql> truncate table db1.t1; //清空表
Query OK, 0 rows affected (0.03 sec)
mysql> select * from db1.t1;
Empty set (0.00 sec)
mysql> desc db1.t1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(4) | YES | | NULL | |
| name | char(40) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> drop table db1.t1;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from db1.t1;
ERROR 1146 (42S02): Table 'db1.t1' doesn't exist
mysql> drop database db1;
Query OK, 0 rows affected (0.00 sec)
[root@gary-tao ~]# mysqldump -uroot -pszyino-123 mysql > /tmp/mysql.sql //备份库
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# mysql -uroot -pszyino-123 -e "create database mysql2" //创建一个新的库
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# mysql -uroot -pszyino-123 mysql2 < /tmp/mysql.sql //恢复一个库
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# mysql -uroot -pszyino-123 mysql2
Warning: Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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 database();
+------------+
| database() |
+------------+
| mysql2 |
+------------+
1 row in set (0.00 sec)
[root@gary-tao ~]# mysqldump -uroot -pszyino-123 mysql user > /tmp/user.sql //备份表
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# mysql -uroot -pszyino-123 mysql2 < /tmp/user.sql //恢复表
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# mysqldump -uroot -pszyino-123 -A > /tmp/mysql_all.sql
Warning: Using a password on the command line interface can be insecure.
[root@gary-tao ~]# less /tmp/mysql_all.sql
[root@gary-tao ~]# mysqldump -uroot -pszyino-123 -d mysql > /tmp/mysql.sql
Warning: Using a password on the command line interface can be insecure.