MySQL学习记录 - guogeWS/tools GitHub Wiki
1.登陆MySQL的指令: mysql -h 主机名 -u 用户名 -p
2.创建数据库指令:create database 数据库名 [其他选项];
如create database testdb;
3.查询已创建的数据库指令:show databases;
4.选择想要操作的数据库指令:use 数据库名;
如use testdb;
或者在登陆的时候 mysql -D 所选择的数据库名 -h 主机名 -u 用户名 -p
5.在数据库中创建表指令:create table 表名称(列声明);
如create table customers (customers_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,first_name TEXT ,last_name TEXT);
6.查询已创建的表指令:show tables;
7.创建用户指令:create user 'testUsr'@localhost identified by '123456';
8.表中插入数据指令:insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);
如INSERT INTO customers (customers_id,first_name,last_name) VALUES (1,"guoxiangzhuo","softWare");
9.显示表中所有数据指令: 如select * from customers;
10.查询表中某一项数据指令: 如search genglei from customers;
11.精确查找指令: 如select * from customers where first_name = "genglei";
select last_name from customers where first_name = 'genglei';
12.查询用户信息指令: select User,host from mysql.user
只能在root用户下使用。
13.通过外网访问用户及旗下数据库: grant all privileges on *.* to 'testUsr'@'%' identified by '123456' with grant option;
别忘了使用 flush privileges;
刷新。