linux tar包安装mysql

添加mysql用户

useradd -s /sbin/nologin -M mysql

解压tar包

tar -zxvf mysql8.tar.gz

my.cnf

[mysqld]
datadir=/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
symbolic-links=0
default_authentication_plugin=mysql_native_password

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

[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
!includedir /etc/my.cnf.d

将各路径创建出来并赋权

mkdir /data
mkdir /var/lib/mysql
mkdir /var/log/mysql
mkdir /var/run/mysql

touch /var/lib/mysql/mysql.sock
touch /var/log/mysql/mysql.log
touch /var/run/mysql/mysql.pid

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

初始化mysql

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

添加环境变量

echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

source /etc/profile.d/mysql.sh

创建开机自启动

chkconfig --add mysqld
chkconfig mysqld on

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

如果没有记住它生成的随即密码,则在/etc/my.cnf中的[mysqld]下加入

skip-grant-tables

然后重启mysqld服务,便可以不输入密码进入

你可能感兴趣的:(数据库,mysql,数据库)