安装环境
linux版本:CentOS 8.+ x64 Mysql:8.0
1. 下载 MySQL 的 Yum 源
下载MySQL的 Yum Repository。 一般需要根据 CentOS
版本选择 MySQL
下载命令:
wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
2. 用 yum命令安装下载好的rpm包。
yum -y install mysql80-community-release-el7-2.noarch.rpm
3. 安装 MySQL Server
yum -y install mysql-community-server
安装过程中可能遇到如下问题
not found 问题
解决办法
yum module disable mysql
后续继续执行
yum -y install mysql-community-server
** Error: GPG check FAILED 问题**
yum -y install mysql-community-server --nogpgcheck
安装完成之后如下:
查看是否安装成功
启动 MySQL 命令
systemctl start mysqld.service
查看 MySQL. 运行状态
systemctl status mysqld.service
其中Active后面代表状态启动服务后为active (running),停止后为inactive (dead)
4. 登陆 MySQL
初识时会给个固定密码,MySQL已经开始正常运行,要进入MySQL还得先找出此时root用户的密码,使用如下命令可以找出密码:
grep "password" /var/log/mysqld.log
操作如下:
[root@iZbp19brmfd0q5cfdumjwlZ software]# grep "password" /var/log/mysqld.log 2022-01-22T04:02:58.667571Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: kpPz&&-ew4Bq
登陆命令
mysql -u root -p
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
新密码设置的时候如果设置的过于简单会报错, 如果想改个简单秘密,需要进行如下操作:
简单说明:
show VARIABLES LIKE 'validate_password%';
密码的长度是由 validate_password_length
决定的 ·validate_password_length的
计算公式如下:
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
validate_password_policy
代表密码策略:
- 默认是1:符合长度,且必须含有数字,小写或大写字母,特殊字符。
- 设置为0判断密码的标准就基于密码的长度了。
要想密码简单,操作如下:
mysql> set global validate_password.policy=0;
validate_password_length代表密码长度,最小值为4
mysql> set global validate_password.length=4;
操作完成后,结果如下:
此时可以设置一个很简单的密码,例如1234
abcd
之类的。
还有一个问题,就是因为安装了 Yum Repository
,以后每次yum
操作都会自动更新,需要把这个卸载掉:
[root@localhost ~]# yum -y remove mysql80-community-release-el7-2.noarch
执行 SQL 时候,还可能遇到一个问题:this is incompatible with sql_mode=only_full_group_by
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yshopb2c.yx_store_order.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ### The error may exist in co/yixiang/modules/order/service/mapper/StoreOrderMapper.java (best guess) ### The error may involve co.yixiang.modules.order.service.mapper.StoreOrderMapper.chartList-Inline ### The error occurred while setting parameters ### SQL: SELECT IFNULL(sum(pay_price),0) as num,DATE_FORMAT(create_time, '%m-%d') as time FROM yx_store_order where refund_status=0 and is_del=0 and paid=1 and pay_time >= ? GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d') ORDER BY create_time ASC ### Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yshopb2c.yx_store_order.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yshopb2c.yx_store_order.create_time' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_fu
问题原因:
通过查阅资料发现是因为下载安装的是最新版的mysql5.7.x版本,默认是开启了 only_full_group_by 模式的,但开启这个模式后,原先的类似 group by语句就报错,然后又把它移除了。就可以了。
操作如下:找到 MySqL 配置文件my.cnf
。增加一行 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
[mysql] default-character-set=utf8 [mysqld] port = 3306 # Binary Logging log-bin=mysql-bin binlog-format=Row #Server ID server-id=201901 #basedir=D:\MySQL\mysql-5.7.14-winx64 #datedir=D:\MySQL\mysql-5.7.14-winx64\data max_connections=200 character-set-server=utf8 default-storage-engine=INNODB skip-grant-tables sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTI
5. 设置 MySQL 外网访问
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
操作如下
mysql> use mysql; mysql> update user set host="%" where user='root'; mysql> flush privileges;
允许外网连接
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234.';
mysql 配置说明
1 /etc/my.cnf 这是mysql的主配置文件 2 /var/lib/mysql mysql数据库的数据库文件存放位置 3 /var/log mysql数据库的日志输出存放位置 4.service mysqld start #启动 5.service mysqld restart #重启 6.service mysqld stop # 停掉
如果还是不能 方法,有可能是 阿里云 权限问题
设置安全组, 首先检查你的阿里或腾讯的服务器控制台是否开启3306端口访问权限,怎么看安全组在哪,自行百度。
连接成功后,结果如下: