mysql常用语句

本地连接数据库

shell> mysql -h host -P port -u root -p

查看数据库包含的所有schemas

mysql> show databases;

连接某个数据库

mysql> use database;

查看数据库包含的所有表

mysql> show tables;

为root用户配置权限

mysql> use mysql;
mysql> create user ‘root’@’%’ identified by ‘password‘;
mysql> grant all privileges on *.* to ‘root’@’%’ with grant option;
mysql> flush privileges; # 重新加载授权表

数据库迁移

  1. 首先导出数据库
    shell> mysqldump –databases your database > sql file
    注意 导出的sql文件,会自动包含create database和use语句, 如果不想包括这两行, 比如需要重新定义数据库名, 去掉–databases选项即可, 如下:
    shell> mysqldump your database > sql file

  2. 导入数据库
    shell> mysql < sql file
    或者登入sql命令行界面输入:
    sql> source sql file
    注意 阿里云云数据库在普通账号下不能直接创建数据库. 需要手动通过官方网站创建数据库, 然后给账号分配读写权限, 再输入上述命令.

表名

表名引用的标准做法是使用反引号进行引用, 这样表名可以使用任意字符串. 否则对于一些特殊表明比如带!等表名, 查询会出错.

Error Code: 1175.

You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
SET SQL_SAFE_UPDATES = 0;

mysqlimport: 大量数据快速导入

mysqlimport -h 192.168.1.201 -u root -p -P 6033 sat refund_unmatched_sales.txt --local
其中, sat为数据库, refund_unmatched_sales.txt为包含大量数据的文本文件, 其文件名必须与数据库的表名相同. –local必须要, 指示refund_unmatched_sales.txt为本地文件, 而非数据库机器上的文件.

root密码忘记解决方法

  • 修改/etc/my.cnf配置文件
    在[mysqld]段增加: skip-grant-tables

  • 重启mysql
    /etc/init.d/mysqld restart

  • 进入mysql修改root密码
    mysql

    use mysql;
    update user password = password(‘your new password’) where user = ‘root’;
    flush privileges;
    quit

  • 改回/etc/my.cnf配置文件

  • 重启mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值