安装好MySQL服务后添加环境变量:
#vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin#source /etc/profile
1.数据库指令:(由于自己习惯用service,需安装指定工具net-tools)
# service mysqld start 启动MySQL
# service mysqld restart 重启MySQL
# service mysqld stop 停止MySQL
2.进入MySQL表单操作
# mysql -h 127.0.0.1-u root -p123456; 进入MySQL(设置好相应密码后)
MySQL> show databases; 列出数据库
MySQL> create database aa; 创建数据库XXXMySQL> use aa; 使用数据库databaseName
MySQL> show tables; 列出表单MySQL> create table mytablename (ID int auto_increment not null primary key,usename varchar(20),password varchar(64),sex varchar(10),address varchar(20)); 创建表单
MySQL> drop table mytablename ; 删除表单
MySQL> drop database aa; 删除数据库
3.增删改查
MySQL> insert into mytablename values(‘‘,‘zhangsan‘,‘123456‘,‘fomale‘,‘guiyanag‘); 插入
MySQL> select * from mytablename ; 查找验证结果
MySQL> select * from mytablename where ID = ‘1‘; 精准查找MySQL> update mytablename set address = ‘shanghai‘ where username = ‘zhangsan‘; 修改zhangsan的address为shanghai
MySQL> delete from mytablename where ID = ‘1‘; 删除记录
新增本地特权用户
grant select on database.* to [email protected]‘localhost‘ identity by ‘password‘;
用户名user_1 密码是123456
可以自任何PC上登录这个用户对数据库操作(举一种方法)
MySQL> grant select,insert update,delete on *.* to [email protected]"%" identity by "123456";
创建只有在本机才能操作数据库的用户
用户名user_2 密码是123456
MySQL> grant select,insert update,delete on *.* to [email protected] identity by "123456";
登录数据库库
MySQL> -u user_1 -p -h IP地址;
另外附上常用的一些命令:
其它的mysql数据库相关的操作如下
(1) 创建数据库czlmysql> create database czl;
(2) 制定czl数据库为当前默认数据库 mysql> use czl;
(3) 在czl数据库中创建表customers mysql> create table customers(userid int not null, username varchar(20) not null);
(4) 显示数据库列表 mysql> show databases;
(5)显示数据库中的表 mysql> show tables;
(6)删除表customers mysql> drop table customers;
(7)显示customers表的结构 mysql> desc customers;
(8) 向customers表中插入一条记录 mysql> insert into customers(userid, username) values(1, ‘chy‘);
(9) 让操作及时生效; mysql> commit;
(10) 查询customers中的记录 mysql> select * from customers;
(11) 更新表中的数据 mysql> update customers set username=‘DennisHu‘ where userid=1;
(12) 删除表中的记录 mysql> delete from customers;
(13)授予chy用户访问数据库的权限 # grant select, insert, update, delete on *.* to [email protected]"localhost" identified by "123456";
原文地址:https://www.cnblogs.com/bbox/p/9697177.html