声明
- 写这篇文章的原因是因为 MySQL 已经升级原命令已经失效,自己则对这部分命令进行修改
- 选择对应系统下载
- 解压之后将名称修改为mysql
- 上传至 linux 服务器
上传路径
/usr/local
创建数据目录
cd /usr/local/mysql
mkdir data
创建用户组
groupadd mysql
useradd -r -g mysql mysql
赋予权限
chown mysql:mysql -R /usr/local/mysql
修改配置文件
vi /etc/my.cnf
将basedir、datadir修改为对应地址
[mysqld]
bind-address=0.0.0.0
user=mysql
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
进入 bin 目录编译文件
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
将mysql.server 拷贝到/etc/init.d/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动
cd /usr/local/mysql/bin
#启动
service mysql start
如若报错
ERROR! The server quit without updating PID file (/usr/local/mysql-8.0.19/data/localhost.pid).
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql /var/log/mariadb/
cd /var/lib
mkdir mysql
chown -R mysql /var/lib/mysql/
重新启动
cd /usr/local/mysql/bin
service mysql restart
修改密码
./mysql -u root -p
#设置密码
ALTER USER USER() IDENTIFIED BY '自己的密码';
#设置远程访问权限
use mysql;
update user set host = '%' where user = 'root';
#退出
\q
#刷新权限
flush privileges;
修改防火墙
#禁用防火墙
systemctl stop firewalld.service
#禁止防火墙开机启动
systemctl disable firewalld.service
网友评论