mysql初级命令

来源:互联网 发布:nosql数据库的优点 编辑:程序博客网 时间:2024/05/01 15:30


修改本地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

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 参加水果展没有实物怎么办 没做过运营面试怎么办 苹果5s16g内存满了怎么办 618天猫有活动淘宝没有怎么办 天猫国际买到假货怎么办 天猫恶意差评怎么办 天猫删除差评被扣分了怎么办 天猫收到差评怎么办 天猫给差评骚扰怎么办 天猫客户差评怎么办 天猫没法给差评怎么办 天猫上限购一件怎么办 拍下商品不发货怎么办 天猫红包过期了怎么办 买天猫店被中介骗了钱怎么办 速卖通假货纠纷怎么办 天猫新开店被恶意拍下怎么办 新开的天猫店没有生意怎么办 银行的支票丢了怎么办 天猫积分用光了怎么办 淘宝店没有无线流量怎么办 京东卖家不发货怎么办会自动打款 一件代发顾客如果退款怎么办 京东以前的账号怎么办 旺旺对话框订单页面变宽了怎么办 阿里巴巴店铺上传图片很模糊怎么办 天猫跨店优惠券用了退货怎么办 淘宝店铺没流量没访客怎么办 京东微信和Q端黑号了怎么办? 买不了运费险了怎么办 拼多多5天不发货怎么办 天猫店手机发货成定制机怎么办 天猫退货上门取件退两件怎么办 买二手苹果手机没有账号怎么办 手机淘宝足迹不更新怎么办 淘宝申请退款不想退了怎么办 荣耀3c主板坏了怎么办 荣耀10天气删了怎么办 荣耀7i手机卡顿怎么办 荣耀v9总是自己拨号怎么办 华为荣耀5x很卡怎么办