• mysql常用命令


    1.net stop 连接名

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

    2.net start 连接名

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

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

    -h : 指定客户端所要登录的 MySQL 主机名, 登录本机(localhost 或 127.0.0.1)该参数可以省略;
    -u : 登录的用户名;
    -p : 告诉服务器将会使用一个密码来登录, 如果所要登录的用户名密码为空, 可以忽略此选项。
    例子:
     C:Windowssystem32>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:Windowssystem32>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:Windowssystem32>mysql --version
    登录数据库
    C:Windowssystem32>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:Systemmysqlmy.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 窗口,转到 mysqlin 目录。 
     3. 输入 mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。
     4. 再开一个 DOS 窗口(因为刚才那个 DOS 窗口已经不能动了),转到 mysqlin 目录。
     5. 输入 mysql 回车,如果成功,将出现MySQL提示符 >6. 连接权限数据库: use mysql;6. 改密码:update user set password=password("123") where user="root";(别忘了最后加分号) 。
     7. 刷新权限(必须步骤):flush privileges; 。 
     8. 退出 quit。 
     9. 注销系统,再进入,使用用户名 root 和刚才设置的新密码 123 登录。
    别废话,拿你代码给我看。
  • 相关阅读:
    Kali Linux下安装配置ProFTPD实例
    mysql 如何用root 登录
    串口总是报'Error opening serial port'
    用SPCOMM 在 Delphi中实现串口通讯 转
    delphi中使用spcomm来实现串口通讯(转载)
    SPCOMM的一些用法注意
    MySQL 字符串 转 int/double CAST与CONVERT 函数的用法
    彻底删除mysql服务
    mysql 非安装版的一个自动安装脚本及工具(更新版)
    bat操作数据库mysql
  • 原文地址:https://www.cnblogs.com/lvxueyang/p/13707396.html
Copyright © 2020-2023  润新知