MySql命令的基本操作

MySQL的基本命令:

登录:mysql  -h -u root -p

        password:*****;

 

例如:mysql -h127.0.0.1 -uroot -p

 

增加一个用户: grant all on databasename.tableName to username@localhost identified by 'password';

增加一个本地用户:insert into mysql.user(Host,User,Password) values("Tonge","test",password("a123"));

增加一个远程用户:grant all privileges on*.* to Tonge@"%" identified by 'a123';

解释:grant all 数据库.表名 to 用户名@域 identified by '密码'

 

2023/12/19补充:

新增用户:create user 'username'@'localhost' identified by 'password';

授权数据:grant all privileges on [database].* to 'username'@'localhost' identified by 'password';

刷新权限:flush privileges;

 

查询所有数据库:show databases;

使用数据库:use databaseName;

查看所有表:show tables;

 

查看表结构:show columns from 表名;

                     select * from columns where table_name='表名';

 

mysql 忘记root密码:

1.先停止mysql服务,使用第2步无验证方式启动:
2.使用cmd进到mysql安装的bin目录执行:mysqld -nt --skip-grant-tables;
3.新启动一个cmd,输入,mysql -uroot -p 回车;
4.选择mysql数据库:use mysql;
5.修改密码:update user set password=password("new_pass") where user="root";
6.刷新权限:flush privileges;
上面步骤如果出现拒绝访问,请尝试用管理员cmd命令窗重试。

注意mysql5.7已经没有password字段了,改为了authentication_string

 update user set authentication_string=password("root") where user="root";

 

mysql 8小时时间差

mysql > SET time_zone = '+8:00';   # 此为我们所在东8区
mysql> flush privileges;   # 立即生效

 或者

mysql安装目录下my.cnf/my.ini的 [mysqld]下的第一行中加上

default-time_zone = '+8:00'

 

posted @ 2014-01-16 17:51  Tonge  阅读(201)  评论(0编辑  收藏  举报