mysql命令
一、初试命令:
show databases; # 查看当前Mysql都有那些数据,根目录都有那些文件夹
create database 数据库名; # 创建文件夹
use 数据库名; # 使用选中数据库,进入目录
show tables; # 查看当前数据库下都有那些表,
create table 表名(nid int,name varchar(20), pwd varchar(64)); # 创建数据库表
select * from 表名; # 查看表中的所有数据
insert into 表名(nid,name,pwd) values(1,‘alex‘,‘123‘); # 插入数据
select * from 表名;
示例:
1 [[email protected] ~]# mysql -uroot -p #再输入密码 2 Welcome to the MySQL monitor. Commands end with ; or \g. 3 Your MySQL connection id is 4 4 Server version: 5.5.49 MySQL Community Server (GPL) 5 6 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 7 8 Oracle is a registered trademark of Oracle Corporation and/or its 9 affiliates. Other names may be trademarks of their respective 10 owners. 11 12 Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. 13 14 15 #创建数据库 16 mysql> create database test1; 17 Query OK, 1 row affected (0.02 sec) 18 19 20 #进入test1库中 21 mysql> use test1; 22 Database changed 23 24 #创建表tb1(nid和name字段) 25 mysql> create table tb1(nid int,name varchar(20)); 26 Query OK, 0 rows affected (0.06 sec) 27 28 #创建tb2 (nid和name字段) 29 mysql> create table tb2(nid int,name varchar(20)); 30 Query OK, 0 rows affected (0.01 sec) 31 32 #查看表 33 mysql> show tables; 34 +-----------------+ 35 | Tables_in_test1 | 36 +-----------------+ 37 | tb1 | 38 | tb2 | 39 +-----------------+ 40 2 rows in set (0.01 sec) 41 42 #查看所有表 43 mysql> select * from tb1; 44 Empty set (0.01 sec) 45 46 #往表中插入数据 47 mysql> insert into tb1(nid,name)values(1,‘alex‘); 48 Query OK, 1 row affected (0.01 sec) 49 50 #往表中插入数据 51 mysql> insert into tb1(nid,name)values(1,‘eric‘); 52 Query OK, 1 row affected (0.01 sec) 53 54 #查看所有表 55 mysql> select * from tb1; 56 +------+------+ 57 | nid | name | 58 +------+------+ 59 | 1 | alex | 60 | 1 | eric | 61 +------+------+ 62 2 rows in set (0.00 sec) 63 64 #退出 65 mysql> exit 66 Bye
二、用户授权
用户管理特殊命令:
创建用户
create user ‘用户名‘@‘IP地址‘ identified by ‘密码‘;
删除用户
drop user ‘用户名‘@‘IP地址‘;
修改用户
rename user ‘用户名‘@‘IP地址‘; to ‘新用户名‘@‘IP地址‘;;
修改密码
set password for ‘用户名‘@‘IP地址‘ = Password(‘新密码‘)
时间: 2024-10-12 19:57:21