您的位置:首页 > 数据库 > MySQL

MySQL 日常操作大型攻略

2016-01-29 16:13 671 查看
1.关于mysql管理员账号

mysql管理员账号默认是root,密码为空。首次设置管理员密码的方法:

mysqladmin -uroot password=‘yourpassword’

2.修改密码(其实就是修改mysql.user表里面的password字段)

mysql> update mysql.user set password=('newpassword') where user='root'


普通用户的修改方法也是一样,这里要注意:要按严格的方式写,不然会导致mysql数据库不见了,恢复方法是skip-grant;还有就是mysql的用户和linux系统的用户是不一样的,我之前就误以为这个root是linux系统里面的root用户。

3.mysql的一些常用操作

查看都有哪些库
show databases;


查看某个库的表
use db; show tables;


查看表的字段
desc tb;
(这个只是看字段名,看不到内容)

查看建表语句
show create table tb;


当前是哪个用户
select user();


当前库
select database();


创建库
create database db1;


创建表
create table t1 (id int(4), name char(40));


查看数据库版本
select version();


查看mysql状态
show status;


修改mysql参数

show variables like 'max_connect%'; set global max_connect_errors = 1000;


查看mysql队列
show processlist;


创建普通用户并授权

grant all on *.* to user1 identified by '123456';
grant all on db1.* to 'user2'@'10.0.2.100' identified by '111222';
grant all on db1.* to 'user3'@'%' identified by '231222';


更改密码

UPDATE mysql.user SET password=PASSWORD("newpwd") WHERE user='username' ;


查询

select count(*) from mysql.user;
select * from mysql.db;
select * from mysql.db where host like '10.0.%';


创建表
create table tablename (id int(10),name char(40),field type);


插入
insert into table value(a,b,c...),(a1,b1,c1...)(...);
这条我试过是可以的,一次性插入多条数据

例如:
insert into table t1 value(1,'hwangchen',22),(2,'Jeong',23),(3,'hz',24);


修改
update database.table field1=value1,field2=value2 where field3=value3;
这个是一次性修改多条内容的语句

例如:
update hwangchen.t1 name='Jeong',age=22 where id=1;


清空表
truncate table db1.t1;


删除表
drop table db1.t1;


删除数据库
drop database db1;


修复表
repair table tb1 [use frm];


4.mysql远程登录

mysql -uroot -h192.168.1.123 -P3306 -ppasword ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 基本操作