MySQL备份和恢复
MySQL常用管理命令
1.创建登录用户
mysql > create user zhangsan@ '%' identified by '123456' ; # %指任意的远程终端
2.测试用户登录
# yum install mysql -y # mysql -uzahngsan -p123456 -h 192.168.109.150
3.用户为自己更改密码
mysql > set passwore=password('新密码')
4.root给其他用户改密码
mysql > set password for zahngsan@'%' =password('新密码')
5.root找回自己的密码并修改
关闭数据库,修改主配置文件(/etc/my.cnf)添加:skip-grant-tables
启动数据库,空密码登录并修改密码
删除skip-grant-tables,重启数据库验证新密码
# vim /etc/my.cnf skip-grant-tables # update mysql.user set password=password('新密码') where user='root' ;
6.创建查询数据库
mysql > create database web; mysql > show databases;
7.创建数据表
mysql > use web; #选择要使用的数据库 mysql > create table a1 (id int , name char(30) , age int ); 复杂点的 mysql> create table a2 (-> id int unsigned not null auto_increment,-> name char(20) not null default '',-> age int not null default 0,-> primary key (id)); Query OK, 0 rows affected (0.01 sec)