一、mac 10.13.4 安装mysql-workbench-community-8.0.11-rc-macos-x86_64.dmg
1)配置密码有强密码模式和弱密码模式,强密码要求必须大小写英文和特殊字符,如Admin_123
2)支持修改为弱密码
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '831015';
FLUSH PRIVILEGES;
root是用户名,localhost是ip地址127.0.0.1都是特指本机,mysql_native_password是旧的密码验证机制,831015是密码,最后别忘了分号;(在MySQL8.0下有效,在MySQL5.7.22无效)
3)更改本地编码
首先停掉MySQL服务,在/etc下新建my.cnf文件,sudo touch my.cdf ,编辑内容如下,保存重启MySQL服务,通过查看字符集可以看到已经发生变化。
[mysqld] [client] default-character-set=utf8 [mysqld] collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' character-set-server = utf8 [mysql] default-character-set=utf8
二、卸载MySQL8.0,安装MySQL5.7.22
1)重装后记得需要重启电脑,MySQL才能顺利启动,否则报错如下:
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
2)Linux下安装后可以通过grep password /var/log/mysqld.log查看默认生成的root密码,而Mac没有这个文件,只能在安装过程中记得拍下生成的临时密码。
3)修改密码,竟然可以修改成功 ,语句如下 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
4) show variables like 'character_set_%';如下:
mysql> show variables like 'character_set_%';
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.22-macos10.13-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.00 sec)
5)show variables like 'collation_%';如下:
mysql> show variables like 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.01 sec)
5)设置表不区分大小写
1、用root登录,修改 /etc/my.cnf;
2、在[mysqld]节点下,加入一行: lower_case_table_names=1
3、重启MySQL即可;
其中 lower_case_table_names=1 参数缺省地在 Windows 中这个选项为 1 ,在 Unix 中为 0,因此在window中不会遇到的问题,一旦一直到linux就会出问题的原因(尤其在mysql对表起名时是无法用大写字母的,而查询用了大写字母却会出查不到的错误,真是弄的莫名其妙)
6)设置可以远程登录
use mysql;
select user,host from user where user = 'root';
update user set host = '%' where user = 'root';
flush privileges;
7)临时修改禁用MySQL强密码验证
set global validate_password_policy=0;
set global validate_password_length=4;
select @@validate_password_length;
create user 'shwmm'@'%' identified by 'shwmm';