linux mysql 安装步骤(规避了一些坑)

本文提供了一份详细的Linux系统上安装MySQL 8.0的步骤,包括下载MySQL安装包,解压,创建用户和组,修改权限,配置my.cnf文件,初始化数据目录,以及启动MySQL服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参照:
    https://www.runoob.com/mysql/mysql-install.html
    https://www.cnblogs.com/shenjianping/p/10984540.html

mysql 获取地址

     https://dev.mysql.com/downloads/mysql/

以下是安装步骤:

#获取mysql

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
tar -xvJf  mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz   -C   /usr/local/mysql

#修改权限
groupadd mysql
useradd -r -g mysql mysql
chown mysql:mysql -R /usr/local/mysql

mkdir -p mysql/data

修改 /etc/my.cnf 具体如下:

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/usr/local/mysql/mysql.sock

default_authentication_plugin=mysql_native_password

# 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

user=mysql
port=3306
character-set-server=utf8

#取消密码验证
skip-grant-tables

[mysqld_safe]
log-error=/var/log/mysql/mariadb.log
pid-file=/var/run/mysql/mariadb.pid


[client]
socket=/usr/local/mysql/mysql.sock
[server]
socket=/usr/local/mysql/mysql.sock

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

 

#因为最开始有修改权限的操作,这一部分如果不修改权限,会出现一些错误

chown mysql:mysql -R /var/log/mysql/

chown mysql:mysql -R /var/run/mysql/


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


#可把mysql 路径添加到PATH


service mysql start

#可以安全启动

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值