修改本地MySQL root密码 #mysqladmin -uroot -p原密码 password 现密码 #mysqladmin -uroot -p passwd password nowwd 修改远程mysql服务器root密码 #mysqladmin -uroot -p passwd -h 192.168.0.188 password nowwd 第一次安装mysql以后通过这条命令可以对mysql进行设置 #mysql_secure_installation 从本机登录mysql数据库 #mysql -uroot -p passwd 创建数据库 mysql>create database mysql; 查询数据库 mysql>show databases; 进入某一数据库 mysql>use mysql; 创建mysql数据库中的表 mysql>create table Linux( >username varchar(15) not null, >password varchar(15) not null >); 显示数据库中的表 mysql>show tables; 查看mysql数据库中的user表的所有内容 mysql>select * from mysql.user 查看user表中的数据结构 mysql>desc user; 在表中插入数据 mysql>insert into table values('user1','password'); 更新table表中的user1的密码 mysql>update table set password=password('passwd2') where username=user1; 删除table表user1的所有 mysql>delete * from table where username=user1 查询user表中的host,user,password字段 mysql>select host,user,password from user; 授权user1密码为passwd1,并且只能在本地查询数据库的所有内容 mysql>grant 权限(select、delete、insert、all。。。) on 数据库.表 to 用户@主机 identified by'密码' mysql>grant select on *.* to user1@localhost identified by 'passwd1' 授权user2密码为passwd2,可以从远程任意主机登录mysql并且可以对MySQL数据库任意操作 mysql>grant all on mysql.* to user2@'%' identified by 'passwd2' 刷新数据库信息 mysql>flush privileges; 备份mysql库到mysql.bak #mysqldump -u root -p passwd mysql > mysqlbak.sql 恢复mysql库 #mysqldump -u root -p passwd mysql< mysqlbak.sql mysql>source mysql.sql mysql密码恢复 #/etc/init.d/mysqld stop #mysqld_safe --skip-grant-tables & //t跳过grant-tables授权表,不需要认证登录本地mysql数据库 mysql>update mysql.user set password=password('passwd') where user='root' //更新root用户密码为passwd #/etc/init.d/mysql start |
|