Linux 安装 Mysql

2022-12-20 18:20:58 来源:51CTO博客

一、下载安装包

安装包下载 ​​https://downloads.mysql.com/archives/community/​​

选择自己要下载的版本下载

二、上传到Linux机器进行解压

tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gzmv mysql-5.7.39-linux-glibc2.12-x86_64 mysql-5.7.39

三、添加系统mysql组和MySQL用户

cat /etc/group | grep mysqlmysql:x:27:cat /etc/passwd | grep mysqlmysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin如无,执行添加命令:groupadd mysqluseradd -r -g mysql mysql

四、安装数据库

1.在解压的MySQL目录下创建data目录


(资料图)

mkdir data

2.将/usr/local/mysql/mysql-5.7的所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql/mysql-5.7

3.在/usr/local/mysql/mysql-5.7/support-files目录下创建my_default.cnf

cd support-files/vim my_default.cnf

并且写入文件,保存覆盖

[mysqld]sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESbasedir = /usr/local/mysql/mysql-5.7datadir = /usr/local/mysql/mysql-5.7/dataport = 3306socket = /tmp/mysql.sockcharacter-set-server=utf8log-error = /usr/local/mysql/mysql-5.7/data/mysqld.logpid-file = /usr/local/mysql/mysql-5.7/data/mysqld.pid

4.初始化 mysqld

cd /usr/local/mysql/mysql-5.7/./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/mysql-5.7.39/data/

5.初始化成功,在日志中查看默认密码

cd /usr/local/mysql/mysql-5.7/data/

6.把启动脚本放到开机初始化目录

cp support-files/mysql.server /etc/init.d/mysql

7.登录mysql,修改密码,添加远程访问权限

见文章:

​​https://blog.51cto.com/u_15227402/5907011​​

8.重启mysql生效

service mysql stop 关闭mysql

service mysql start 开启mysql

service mysql restart 重启mysql

标签: 远程访问 修改密码 默认密码

上一篇:天天新动态:如何使用 Spring 创建“Hello, World”RESTful Web 服务
下一篇:全球新资讯:通过Console口登录设备