目录
下载
安装步骤
上传
解压安装
参考资料
补充报错解决
下载
MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/
安装步骤
上传
使用xshell,连接服务器,用 rz命令接收下载的文件(该命令使用 yum -y install lrzsz 安装)
解压安装
- 文件格式为xz,需要使用 yum -y install xz
- 创建解压目录 mkdir -p /usr/local/mysql
- xz解压 xz -d ./mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
- tar解压 tar -xvf ./mysql-8.0.31-linux-glibc2.12-x86_64.tar -C /usr/local/mysql
- 解压后文件夹名称修改,mv /usr/local/mysql/mysql-8.0.31-linux-glibc2.12-x86_64 /usr/local/mysql/mysql-8.0.31
- 创建数据目录 mkdir -p /usr/local/mysql/mysql-8.0.31/data
- 创建用户组 groupadd mysql
- 创建用户 useradd -g mysql mysql
- 修改权限 chown -R mysql.mysql /usr/local/mysql/mysql-8.0.31
- 拷贝
mysql.server
至/etc/init.d/mysql
添加mysqld服务到系统 cp /usr/local/mysql/mysql-8.0.31/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --level 2345 mysql on #设置开启自动启动 - 编辑 my.cnf 文件 vim /etc/my.cnf
[client] default-character-set=utf8mb4 # password = your_password port= 3306 socket=/var/lib/mysql/mysql.sock # The MySQL server [mysqld] # 配置mysql的文件夹 和 mysql data目录 basedir=/usr/local/mysql/mysql-8.0.31 datadir=/usr/local/mysql/mysql-8.0.31/data default-storage-engine=INNODB character-set-server=utf8mb4 collation-server=utf8mb4_general_ci port=3306 socket=/var/lib/mysql/mysql.sock skip-external-locking key_buffer_size=16K max_allowed_packet=64M table_open_cache=4 sort_buffer_size=64K read_buffer_size=256K read_rnd_buffer_size=256K net_buffer_length=2K thread_stack=128K bind-address=0.0.0.0 server-id=1 # Uncomment the following if you want to log updates # log-bin=mysql-bin # binary logging format - mixed recommended # binlog_format=mixed [mysqldump] quick max_allowed_packet = 64M [mysql] default-character-set=utf8mb4 no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size=8M sort_buffer_size=8M [mysqlhotcopy] interactive-timeout
-
初始化,获取初始化密码。cd /usr/local/mysql/mysql-8.0.29/bin/ && ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-8.0.31 # 执行结束后,控制台有密码,供初次登录使用,后续步骤15进行修改密码。
-
启动mysql ./mysqld_safe --user=mysql
-
添加mysql客户端软链 ln -sf /usr/local/mysql/mysql-8.0.31/bin/mysql /usr/bin # f参数强制执行,如果存在该软链,会直接覆盖掉
-
修改初始化密码 ./mysql -uroot -p 上面初始化的密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; use mysql; update user set host='%' where user='root'; flush privileges;
-
开放端口 (在mysql 界面外输入) firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
参考资料
- Centos8安装MySQL8_子非鱼yy的博客-CSDN博客_centos8安装mysql8
- mysql初次不能登录解决方法-木庄网络博客
- mysql程序之mysqld_safe详解 - 走看看
- https://huaweicloud.csdn.net/633564fcd3efff3090b55608.html
补充报错解决
如果有报错如下:
[ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11
参考资料链接【2】中执行方式 mysqld_safe
--user=mysql --skip-grant-tables --skip-networking &
如有报错如下:
Can't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
需要添加/etc/my.cnf 文件中 socket值对应的目录,并授权访问权限 chmod 777 -R /socket_value
另外
排查故障时会用到 ps aux |grep mysql 进程搜索指令
netstat
-tl |
grep
mysql
端口监听指令
链接【3】中位 mysqld_safe 讲解