Linux 安装Mysql

1. 下载源包

wget   https://dev.mysql.com/get/Downloads/MySQL-8.0.20/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

2. 解压tar包,移动到 /usr/local

tar -xvf  mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

mv  mysql-8.0.20-linux-glibc2.12-x86_64   /usr/local/mysql

3. 修改mysql 安装目录权限

chmod -R 755 /usr/local/mysql

4. 创建mysql 数据存储目录并授权

mkdir -p  /data/mysql

chmod 777 /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
#socket=/data/mysql/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
interactive_timeout=28800
wait_timeout=28800
max_connect_errors=9999
[mysqld_safe]
log-error=/data/mysql/mariadb.log
pid-file=/data/mysql/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

6.创建用户 &用户组

groupadd mysql

useradd -g mysql mysql

7.初始化mysql,拿到零时密码

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

cat /data/mysql/mysql.err

8.注册mysql 启动服务并启动

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

service mysql start

9.登录并修改密码

./bin/mysql -u root -h 127.0.0.1 - P13306 -p testPaww

ALTER USER 'root'@'localhost' IDENTIFIED BY 'testPaww';

FLUSH PRIVILEGES;

9.开放远程连接

use mysql;

update user set user.Host='%' where user.User='root';

flush privileges;

10. 创建用户并授权

CREATE USER 'eagle'@'%' IDENTIFIED BY 'testPaww';

GRANT all ON *.* TO 'eagle'@'%';

你可能感兴趣的:(Linux 安装Mysql)