下载官方 Mysql 包
1. 下载mysql MySQL :: Download MySQL Community Server (Archived Versions)
选择对应的包 如下5.7包
2. 上传解压(解压后可删除安装包,节省空间) 2. 上传解压(解压后可删除安装包,节省空间)
tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
3. 先检查是否有mysql用户组和mysql用户,没有就添加有就忽略:
groups mysql
添加用户组和用户 groupadd mysql && useradd -r -g mysql mysql
4.创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
5.修改配置文件 vim /etc/my.cnf (没有就新建
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
6. 初始化
解压后的mysql-5.7.35-linux-glibc2.12-x86_64文件移动到/usr/local/mysql (文件夹名称修改为mysql不带版本号信息)
cd /usr/local/mysql/bin/
./mysqld –defaults-file=/etc/my.cnf –basedir=/usr/local/mysql/ –datadir=/data/mysql/ –user=mysql –initialize
7. 查看初始密码
cat /data/mysql/mysql.err
8. 启动mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
9、cd /usr/local/mysql/bin
./mysql -u root -p
输入默认密码
10、修改默认密码为root
alter user user() identified by “root”;
11. 刷新规则允许外部访问
use mysql #选择访问mysql库
update user set host = ‘%’ where user = ‘root’; #使root能再任何host访问
FLUSH PRIVILEGES; #刷新
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/282949.html