mysql常用命令

1.net stop 连接名

例子:
 C:\Windows\system32>net stop mysql0815
 运行结果如下:
    MySQL0815 服务正在停止.
    MySQL0815 服务已成功停止。

2.net start 连接名

例子:
 C:\Windows\system32>net start mysql0815
 运行结果如下:
    MySQL0815 服务正在启动 .
    MySQL0815 服务已经启动成功。

3.mysql -h localhost -P 3306 -u root -p

-h : 指定客户端所要登录的 MySQL 主机名, 登录本机(localhost 或 127.0.0.1)该参数可以省略;
-u : 登录的用户名;
-p : 告诉服务器将会使用一个密码来登录, 如果所要登录的用户名密码为空, 可以忽略此选项。
例子:
 C:\Windows\system32>mysql -h localhost -P 3306 -u root -p
 Enter password: ****
 运行结果如下:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.5.15 MySQL Community Server (GPL)
    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    

4.exit

例子:
 mysql> exit
 运行结果如下:
    Bye
    C:\Windows\system32>mysql -h localhost -P 3306 -u root -proot
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.5.15 MySQL Community Server (GPL)
    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
展示数据库
mysql> show databases; 
使用数据库

mysql> use test;

展示表
mysql> show tables; 
选择数据库
mysql> select database();
创建表
mysql> create table stuinfo(
    -> id int,
    -> name varchar(20));
查看表的结构
mysql> desc stuinfo;
查询数据
select * from stuinfo;
插入数据
insert into stuinfo (id,name) values(2,'rose');
更新数据
update stuinfo set name='lilei' where id=1;
删除数据
delete from stuinfo where id=1;
选择数据库版本
select version();
在cmd查看数据库版本
C:\Windows\system32>mysql --version
登录数据库
C:\Windows\system32>mysql -uroot -p
Enter password: ****
重启 MySQL 服务:
service mysql restart
忘记 MySQL 密码
打开 my.cnf 配置文件,找到 [mysqld]
然后在该行下面添加以下参数:
skip-grant-tables
重启 MySQL 服务:
刷新权限
flush privileges;  

常见错误:

1.编码错误

mysql Found option without preceding group in config file D:\System\mysql\my.ini at line 1
解决:请将 my.ini 文件格式转为 ANSI 编码。 

2.时区错误

The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone. You must 
configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more 
specifc time zone value if you want to utilize time zone support.
需要在配置文件 [mysqld] 中加入:
default-time-zone = '+8:00'

3.在键入任何命令都会报这个错的时候:

You must reset your password using ALTER USER statement before executing this statement.
意思是需要重设密码,重设密码的命令如下:
alter user user() identified by "密码";

MySQL 修改 root 密码的 4种方法

1.用 SET PASSWORD 命令

首先登录MySQL。
格式:
mysql> set password for 用户名@localhost = password('新密码');

2.用 mysqladmin

格式:
mysqladmin -u用户名 -p旧密码 password 新密码

3.用 UPDATE 直接编辑 user 表

首先登录MySQL。 
mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges;

4.在忘记 root 密码的时候,可以这样,以 windows 为例:

 1. 关闭正在运行的 MySQL 服务。 
 2. 打开 DOS 窗口,转到 mysql\bin 目录。 
 3. 输入 mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。
 4. 再开一个 DOS 窗口(因为刚才那个 DOS 窗口已经不能动了),转到 mysql\bin 目录。
 5. 输入 mysql 回车,如果成功,将出现MySQL提示符 >6. 连接权限数据库: use mysql;6. 改密码:update user set password=password("123") where user="root";(别忘了最后加分号) 。
 7. 刷新权限(必须步骤):flush privileges; 。 
 8. 退出 quit。 
 9. 注销系统,再进入,使用用户名 root 和刚才设置的新密码 123 登录。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值