mysql常用操作命令
2。设置及登录
mysql_secure_installation ##第一次安装mysql以后通过这条命令可以对mysql进行初始设置
mysql -uroot -predhat ##从本机登录mysql数据库(ps -aux|grep mysql kill -9 )
mysqladmin -uroot -predhat password westos ##修改本地mysql,root密码
mysqladmin -uroot -predhat -h 172。
25。8。1 password westos ##修改远程172。25。8。1mysql服务器,root密码
3。操作命令
库操作:
show databases; ##显示数据库
use mysql; ##进入数据库(按回车键出现Database changed时说明操作成功!)
show tables; ##显示数据库中的表
desc user; ##查看user表的结构
flush privileges; ##刷新数据库信息
select host,user,password from user; ##查询user表中的host,user,password字段
create database westos; ##创建westos数据库
use westos; ##进入数据库westos
表操作:
create table linux( ##创建表,表名linux,字段username,password
username varchar(15) not null,
password varchar(15) not null);select * from mysql。
user; ##查询mysql库下的user表中的所有内容alter table linux add age varchar(4); ##添加age字段到linux表中desc linux; ##查看linux表结构ALTER TABLE linux DROP age ##删除linux表中的age字段ALTER TABLE linux ADD age VARCHAR(4) AFTER username ##在linux表username字段后添加字段agedesc linux; ##查看linux表结构
insert into linux values (‘user1‘,18,‘passwd1‘); ##在linux表中插入username=user1,age=18,password=password1
update linux set password=‘passwd2‘ where username="user1"; ##更新linux表中user1的密码为password2
delete from linux where username=‘user1‘; ##删除linux表中user1的所有内容
select * from linux; ##可以进行查看
用户管理:
CREATE USER hjy@localhost identified by ‘westos‘; ##创建本地用户hjy并添加密码westos,默认密码是加密的
CREATE USER hee@‘%‘ identified by ‘redhat‘; ##创建用户hee,%表示这个账户可以在任何主机登录
select host,User,Password from user; ##查询user表中的host,user,password字段
grant select on *。
* to user1@localhost identified by ‘passwd1‘; ##授权user1,密码为passwd1,并且只能在本地查询数据库的所在内容
grant all on mysql。* to user2@‘%‘ identified by ‘passwd2‘; ##授权user2,密码为passwd2,可以从远程任意主机登录mysql并且可以对mysql数据库任意操作(%改为ip可指定此ip登录)
FLUSH PRIVILEGES; ##重载授权表
SHOW GRANTS FOR hjy@localhost; ##查看用户授权
REVOKE DELETE,UPDATE,INSERT on mysql。
* from hjy@localhost; ##撤销用户对mysql的DELETE,UPDATE,INSERT权限
REVOKE all on mysql。* from hjy@localhost; ##撤销用户所有权限
DROP USER hjy@localhost; ##删除用户
备份
/var/lib/mysql
mysqldump -uroot -predhat --all-databases ##命令备份所有数据
mysqldump -uroot -predhat mysql > mysql。
bak ##备份mysql库导到mysql。bak
mysql -uroot -predhat -e "create database westos;" ##创建一个数据库
mysql -uroot -predhat westos < mysql。
bak ##恢复mysql。bak到westos库密码恢复
/etc/init。d/mysqld stop
mysqld_safe --skip-grant-tables & ##跳过grant-tables授权表,不需要认证登录本地mysql数据库
update mysql。
user set password=password(‘westos‘) where user=‘root‘; ##更新mysql。user表中条件root用户的密码为westos
/etc/init。d/mysql restart ##重新启动nysql本文出自 “12148275” 博客,请务必保留此出处http://12158275。
blog。51cto。com/12148275/1910441mysql常用操作命令。
答:详情>>
答:已知的多入牛毛,未知的或许等你开发。详情>>
答:炒股,买卖期货,开网络店铺。呵呵。。详情>>