阿里云centos7 中安装mysql8
1. 首先进入官网,下载对应的安装包,官网地址:https://dev.mysql.com/downloads/mysql/
2.点击 No thanks, just start my download 进行下载(建议使用第二种方法)
(1) 可以手动下载,使用xftp工具上传到云服务的安装目录下(下载速度较慢)
(2) 首先进入阿里云安装目录,使用wget命令进行下载
进入安装目录:cd /usr/local/
在线下载:wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
3. 使用解压命令,将下载的安装包进行解压
解压命令:tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
4. 解压完毕,新建mysql用户,并赋予权限
重命名命令:mv mysql-8.0.21-linux-glibc2.12-x86_64/ mysql-8.0
新建data目录用于存放数据库文件: mkdir /usr/local/mysql-8.0/data
创建mysql属组:groupadd mysql
设置用户权限:useradd -g mysql -s /usr/sbin/nologin mysql
#不让mysql用户直接登录
赋予mysql权限:chown -R mysql:mysql /usr/local/mysql-8.0/
给mysql用户设置密码
[root@iZwz99ujl2isnn729yhqc6Z support-files]# passwd mysql
Changing password for user mysql.
New password: 输入新的密码
BAD PASSWORD: The password is a palindrome
Retype new password: 确认新的密码
passwd: all authentication tokens updated successfully.
5. 修改mysql配置文件,复制以下配置
编辑配置文件命令:vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql-8.0
datadir = /usr/local/mysql-8.0/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-error = /usr/local/mysql-8.0/data/error.log
pid-file = /usr/local/mysql-8.0/data/mysql.pid
user = mysql
tmpdir = /tmp
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
6. 赋予mysql执行权限
赋予权限命令:chmod +x /usr/local/mysql-8.0
7. 配置开机自动启动
复制服务到etc的init目录:cp /usr/local/mysql-8.0/support-files/mysql.server /etc/init.d/mysqld
赋予执行权限:chmod +x /etc/init.d/mysqld
增加mysql服务:chkconfig --add mysqld
赋予自启服务:chkconfig --level 2345 mysqld on
查看服务等级:chkconfig --list mysqld
#查看是否已应用上
8. 添加MySQL的软链接以适应init脚本,配置环境变量(软链接)
ln -sv /usr/local/mysql-8.0/bin/mysql /usr/sbin/mysql
ln -sv /usr/local/mysql-8.0/bin/mysqladmin /usr/sbin/mysqladmin
ln -sv /usr/local/mysql-8.0/bin/mysqldump /usr/sbin/mysqldump
9. 初始化mysql数据库
(1) 初始化命令:/usr/local/mysql-8.0/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-8.0 --datadir=/usr/local/mysql-8.0/data
(2) 查看日志中的初始密码(这个密码就是root的初始密码,先复制出来,下面会用到
)
查看日志命令:cat /usr/local/mysql-8.0/data/error.log
10 . 启动mysql,启动命令:./support-files/mysql.server start
如若启动不成功,记得去查看mysql-8.0/data/error.log 错误日志(每个人的错误可能都不相同)
成功启动如下图所示
11. 登录mysql,并配置成可远程连接
(1) 登陆mysql命令(密码就是上面error.log日志中查看的):./bin/mysql -uroot -p
(2) 使用mysql库:use mysql;
(3) 修改root密码(注意是英文符号)
alter user 'root' @'localhost' identified by 'a';
(4) 修改localhost为%(改为远程登录)
update user set host='%' where Host='localhost' and User='root';
(5) 设置远程连接权限
GRANT ALL ON *.* TO 'root'@'%';
(6) 刷新MySQL的系统权限
flush privileges;
12. 配置防火墙
(1) 配置防火墙,开启3306端口
# 先关闭防火墙,后编辑配置
systemctl stop firewalld.service
vim /etc/sysconfig/iptables
# 添加如下规则到22端口这条规则的下面即可
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
(2) 重启防火墙(注意云上一定要开启防火墙,注意保护端口
)
systemctl start firewalld.service
(3) 启动MySQL
service mysqld start # 或 /etc/init.d/mysqld start
(4) 测试MySQL是否启动,查看是否有mysql进程
ps -ef | grep mysql
(5) 查看是否有mysql端口
netstat -ntlp | grep 3306
(6) 使用远程连接工具进行连接测试mysql,能正常使用
如若连接不上可使用重启命令,使阿里云之前配置生效:reboot
到此MySQL8安装完成,因为8是最新版本,里面有很多坑,将正确的安装方法记录在csdn中。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/13709.html