MySQL使用
- 登录:
mysql -u root -p
- 查看数据库:
show databases;
- 创建数据库:
create database test;
- 查看用户:
select User from mysql.user;
- 创建用户:
create user 'user'@'%' identified with mysql_native_password by 'password';
(使用工具连接数据库不会出现有关密码的错误)
- 用户赋予权限:
grant all privileges on *.* to 'user'@'%';
flush privileges;
MySQL表操作
- 查询某张表的所有数据:
select * from `table`;
- 查询某张表的指定列数据:
select a,b from `table`;
- 查询符合某种条件的数据:
select a,b from `table` where a="1" and (b like "%abc%" or c like "%def%");
- 删除表所有数据:
delete from `table`;
- 统计表数据数量:
select count(*) from `table`;
- 本地txt文件导入数据库:
load data infile "D:/data/data.txt" into table test;
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.