win 安装 mysql:
https://www.yuque.com/u848970/ide/mysql_install
压缩包解压后
目录新建 my.ini 设置data 与 mysql 位置
配置环境变量 %MYSQL_HOME%\bin
到 bin 目录管理员身份执行 mysqld —install
遇到 ERROR 1045 设置 my.ini
skip-grant-tables
net stop mysql net start mysql 重启
连接后修改root密码
use mysql;
alter user ‘root’@’localhost’ identified by ‘你的密码’;
flush privileges;
在win 系统下,python 2 要 mysqlclient pip安装会失败,需要手动下载,在本地使用pip安装
下载链接:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
导出数据库sql:
mysqldump -uroot -p123123 mjtt>mjtt.sql
mysql导入报@@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty错误:
原因是阿里云rds自带主从复制,开启了gtid全局事务id用于保证主从复制一致,备份的时候没有忽略gtid,导致导入本地时报错。
加上—set-gtid-purged=OFF参数再备份,这样就忽略:
mysqldump --set-gtid-purged=OFF
scp:
scp root@101.200.125.164:/tmp/mjtt.sql ~/Desktop/mjtt.sql
mysql> create database abc; # 创建数据库
mysql> use abc; # 使用已创建的数据库
mysql> set names utf_8_mb4; # 设置编码
mysql> source /home/abc/abc.sql # 导入备份数据库
查看表结构:
desc task_archivepackage;
查看建表语句:
show create table radio_audioanchor;
查看
删除字段:
ALTER TABLE table_name DROP field_name;
查看表 编码:
show full columns from people_invitationcode;
删除外键:
alter table radio_audioanchor drop foreign key xxx;
查看mysql的相关系统变量:
SHOW VARIABLES WHERE Variablename LIKE ‘character_set%’ OR Variable_name LIKE ‘collation%’;
| Variable_name | Value |
+—————————————+——————————————+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
修改以上字符集:
SET character_set_client = utf8mb4;
配置 默认字符集:
locate my.cnf
cd /etc/mysql/mysql.conf.d/
vim mysqld.cnf
拉倒最后
collation-server = utf8mb4_general_ci
init-connect=’SET NAMES utf8mb4’
character-set-server = utf8mb4
重启 mysql
service mysql restart
修改 database 数据库字符集:
ALTER DATABASE mjtt CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
修改 字段 字符集:
ALTER TABLE people_invitationcode CHANGE code code varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
修改 表 字符集:
ALTER TABLE payment_mtorder CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;