-
登录
mysql -u root -p -h [主机名] # 然后输入密码 -
查看数据库
show databases; -
创建数据库
mysqladmin -u root -p123456 create test_base; -
推荐:
create database test_base; -
选中数据库
use test_base; -
查看当前所在的数据库
status (推荐) select database(); -
删除数据库
drop database test_base; -
查看有哪些表
show tables; -
创建表
(推荐) create table test_table(num int, temperature float); create table `test_table`(`num` int, `temperature` float); -
创建带字符串的表
create table TemperatureItem(name char(50), epic_id char(4), temperature float, count int, rssi tinyint, antena tinyint, coach_num int, timestamp bigint); -
查看数据表有哪些项
desc test_table; -
删除表
drop table test_table; -
表插入信息
insert coach_temp_table values (1, 20); -
查看表中的所有信息
select * from coach_temp_table; -
只查某项
select coach_num from coach_temp_table; -
删除某一条记录, where 后面是删除的条件子句
delete from coach_temp_table where coach_num = 1; -
加载
.sql文件source *.sql;
数据库添加用户,与修改密码
-
查看用户
select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user; -
添加用户
create user "用户名"@"IP地址" identified by "密码"; # 比如 create user 'admin'@'%' identified by 'root'; -
授权
grant 权限类型 on 数据库名.表名 to '用户名'@'ip地址' identified by '用户密码' with grant option; grant all on *.* to 'admin'@'%'; -
更改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; # 推荐 ALTER USER 'root'@'%' IDENTIFIED BY '123456'; -
删除用户
drop user admin;