目录

MySQL常用操作记录

记录一下日常工作中常用到的MySQL语句和一些配置等,方便日后查询

用户授权相关

创建用户

修改密码

授权

Grant all privileges on *.* to 'root'@'%' with grant option;

授权的同时修改密码

Grant all privileges on *.* to 'root'@'%' identified by 'com.012' with grant option;

库相关

建库

CREATE DATABASE `idp_app` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE DATABASE `idp_sdk` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';

配置文件相关

apt安装的mysql配置文件在/etc/mysql/mysql.conf.d/mysqld.cnf

初始化密码

ubuntu系统通过apt安装的mysql,需要切换到root,然后执行mysql命令就可以登录(不用密码),对应的用户是root@localhost
当然也可以cat /etc/mysql/debian.cnf查看密码。

表名强制转换为小写

仅适用于MySQL 5.7 及以下版本,到了 8.0,只支持初始化时指定该参数,初始化之后,如果修改了该参数,启动就会报错。

配置文件在[mysqld]下面新增一行

[mysqld]
lower_case_table_names = 1

可以通过执行sql查看是否设置成功

show variables like 'lower_case_table_names';

binlog

查看binlog状态

MySQL [(none)] > show variables like 'log_bin%';
+---------------------------------+------------------------------------+
| Variable_name                   | Value                              |
+---------------------------------+------------------------------------+
| log_bin                         | ON                                 |
| log_bin_basename                | /data/mysql/binlog/mysql_bin       |
| log_bin_index                   | /data/mysql/binlog/mysql_bin.index |
| log_bin_trust_function_creators | OFF                                |
| log_bin_use_v1_row_events       | OFF                                |
+---------------------------------+------------------------------------+
5 rows in set (0.02 sec)

查看binlog模式

MySQL [(none)] > show variables like '%binlog_format%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
1 row in set (0.00 sec)

binlog配置文件

[mysqld]
server_id = 1
log_bin = /var/log/mysql/mysql-bin.log
max_binlog_size = 1G
binlog_format = row
binlog_row_image = full