MySQL 问题总结

MySQL

# 更改数据库字段类型
alter table 表名 modify column 字段名 新字段类型;
alter table exec_results modify column body longtext;

# 新增字段
alter table exec_history add mark int(11);

查看用户权限  show grants for wang;
赋予用户权限  GRANT ALL PRIVILEGES ON `libra1`.* TO 'wang'@'%'
重置密码:
  1.service mysqld stop    # 关闭服务
  2.mysqld --user=mysql --skip-grant-tables --skip-networking &
  3.mysql    # 不需要密码进入MySQL
  4.update mysql.user set authentication_string=password('123456') where user='root';
  # 更改数据库密码,mysql5.7以后没有password字段,更换成 authentication_string
  5.退出重新登陆

# 查看最近所有 sql 进程
show full processlist;
# 结束某个执行的进程
kill 345    # kill 进程号

collate 问题

MySQL数据库报错处理:修改表的 collate
# 1267, "Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '='"
问题:数据库中做 连表 的字段格式不一样
原则:修改数据库的collation,对修改后新建的表才会生效,已存在表不生效
     修改表的 collation,对修改后新建的字段才会生效,已存在字段不生效
     修改字段的 collation,对修改后新写入生效,同时对已存在的也生效

代码如下:
ALTER DATABASE `basename` CHARACTER SET utf8COLLATE utf8_bin;
ALTER TABLE `basename`.`tablename`  COLLATE=utf8_bin;
ALTER TABLE `tablename` MODIFY COLUMN `name`  varchar(8) CHARACTER SET utf8 COLLATE utf8_bin;

同时也可以在my.cnf中修改 collation_server             = utf8_bin (重启生效) 
该参数不支持动态修改。
如果需要修改表很多,可以使用导出导入的方式,修改表的collation后导出,重新建表导入时字段将遵循表的collation

windows电脑启动MySQL 的时候报错问题解决

# 问题一:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    
表示密码错误,重新输入正确密码

# 问题二
D:MySQLmysql-5.7.28in>net start mysql 服务名无效。
解决:使用管理员打开cmd,执行 >> mysqld --install,提示 Service successfully installed,表示安装成功,然后执行 net start mysql 启动 MySQL 服务

# 问题三
Install/Remove of the Service Denied!
解决:在管理员下执行cmd,执行 >> mysqld --install

创建表参考

CREATE TABLE `product_net_values` (
  `_id` int(11) NOT NULL AUTO_INCREMENT,
  `trading_at` date DEFAULT NULL,
  `amac_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `unit_net_value` double DEFAULT NULL,
  `acc_net_value` double DEFAULT NULL,
  `cnt` bigint(20) DEFAULT NULL,
  `asset_net_value` bigint(20) DEFAULT NULL,
  `bank_savings` decimal(20,0) DEFAULT NULL,
  PRIMARY KEY (`_id`),
  KEY `idx_amac_id` (`amac_id`)
) ENGINE=InnoDB AUTO_INCREMENT=61449 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
原文地址:https://www.cnblogs.com/whkzm/p/14790746.html