目录
说明:安装软件使用(mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz)
说明:安装软件使用(mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz)
1、standalone基础安装
1.1、下载安装文件并解压
在10.10.10.88的/home目录执行下载命令
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
文件进行解压操作
第一步解压:
xz -d mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
第二步解压:
tar -xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar
重命名:
mv mysql-8.0.31-linux-glibc2.12-x86_64 mysql8
1.2、创建MySQL安装的根目录
mkdir -p /home/mysql
mkdir -p /home/mysql/pid
mkdir -p /home/mysql/binlog
mkdir -p /home/mysql/logs
mkdir -p /home/mysql/data
mkdir -p /home/mysql/relaylog
mkdir -p /home/mysql/socket
mkdir -p /home/mysql/innodb_log_group
touch /home/mysql/logs/mysql.log
mkdir -p /home/mysql/undolog
cp -r /home/mysql8/* /home/mysql/
chown -R mysql:mysql /home/mysql/
1.3、创建MYSQL用户和组
groupadd mysql
useradd -r -g mysql mysql
1.4、授予MYSQL用户的目录权限
chown -R mysql:mysql /home/mysql/
1.5、设置MySQL的环境变量
export MYSQL_HOME=/home/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile
1.6、在etc下创建my.cnf文件
[mysql] default-character-set=utf8mb4 [client] port=3306 socket=/home/mysql/socket/mysql.sock [mysqld] port=3306 server-id=3306 log_bin=mysql-bin binlog_format=MIXED expire_logs_days = 15 max_binlog_size = 100m binlog_cache_size = 4m max_binlog_cache_size = 512m user=mysql #是否对sql语句大小写敏感,1表示不敏感 lower_case_table_names=0 pid-file=/home/mysql/pid/mysql.pid socket=/home/mysql/socket/mysql.sock basedir=/home/mysql datadir=/home/mysql/data log-bin=/home/mysql/mysql-bin innodb_data_home_dir=/home/mysql innodb_log_group_home_dir=/home/mysql character-set-server=utf8mb4 slow_query_log=ON slow_query_log_file=/home/mysql/logs/slow.log long_query_time=2 autocommit=1 symbolic-links=0 max_allowed_packet=512M max_connections=4000 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION [mysqld_safe] log-error=/home/mysql/logs/mysql.log pid-file=/home/mysql/pid/mysql.pid sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
1.7、MySQL数据初始化
/home/mysql8/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql --initialize-insecure
1.8、可执行文件复制
cp -r /home/mysql8/* /home/mysql/
cp /home/mysql/support-files/mysql.server /etc/init.d/mysql
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chown -R mysql:mysql /home/mysql
1.9、修改密码并设置远程访问
启动MYSQL服务
/etc/init.d/mysql start
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
1.10、设置MySQL服务开机启动
cp /home/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
chkconfig --list
ps -ef | grep mysql