Linux系统中MySQL的常用操作命令
服务:
# chkconfig --list 列出所有系统服务
# chkconfig --list | grep on 列出所有启动的系统服务# chkconfig --list mysqld
# whereis mysql 查看文件安装路径
# which mysql 查询运行文件所在路径(文件夹地址)
usr/bin/mysql 是指:mysql的运行路径
var/lib/mysql 是指:mysql数据库文件的存放路径
usr/lib/mysql 是指:mysql的安装路径
添加环境变量:
# vi /etc/profile
# export mysql_home=/usr/local/mysql
# export path=$path:$mysql_home/bin
1.数据库指令:
# service mysqld start 启动mysql
# service mysqld restart 重启mysql
# service mysqld stop 停止mysql
2.进入mysql表单操作
# -u root -p /mysql -h localhost -u root -p databasename; 进入mysql
mysql> show databases; 列出数据库
mysql> create database xxx; 创建数据库xxxmysql> use databasename; 使用数据库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 databasename; 删除数据库
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 identity by 'password'
用户名user_1 密码是123456
可以自任何pc上登录这个用户对数据库操作
mysql> grant select,insert update,delete on *.* to " identity by "123456";
创建只有在本机才能操作数据库的用户
用户名user_2 密码是123456
mysql> grant select,insert update,delete on *.* to identity by "123456";
登录数据库库
mysql> -u user_1 -p -h ip地址;
另外附上常用的一些命令我列一下仅供参考:
其它的mysql数据库相关的操作如下
(1) 创建数据库testdb mysql> create database testdb;
(2) 制定testdb数据库为当前默认数据库 mysql> use testdb;
(3) 在testdb数据库中创建表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, 'hujiahui');
(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)授予likui用户访问数据库的权限 # grant select, insert, update, delete on *.* to likui@localhost indentified by "123456";