Mysql operation and maintenance notes
The official version of MySQL 8 8.0.11 has been released. The official said that MySQL 8 is 2 times faster than MySQL 5.7, and it also brings a lot of improvements and faster performance!
Before Mysql 5.7, utf8 was used, after 8.0, the default encoding was used to use utf8mb4, utf8mb4 is more complete, including utf8
Server initialization
#Adjust swap
echo 0 > /proc/sys/vm/swappiness
vim /etc/sysctl.conf
vm.swappiness = 0
#Installation package
yum install -y cmake gcc gcc-c++ ncurses ncurses-devel bison zlib zlib-devel libxml openssl openssl-devel automake autoconf make libtool bison-devel libaio-devel
#Create user
useradd -s /sbin/nologin mysql
Unzip the file after downloading
#下载
cd /opt
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
# 解压分两步
xz -d mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
tar xf mysql-8.0.23-linux-glibc2.12-x86_64.tar
mv mysql-8.0.23-linux-glibc2.12-x86_64 /usr/local/mysql
System Configuration
#MysqlFile Directory
cd /usr/local/
chown -R mysql. mysql#Data Directory
mkdir -p /data/mysql/3306/data /data/mysql/3306/binlog
chown -R mysql. /data/mysql
#Modify environment variables
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/mysql.sh
Start with system association
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/3306/my.cnf
LimitNOFILE = 5000systemctl daemon-reload
systemctl enable mysqld
Mysql configuration file
cat my.cnf
[client]
port = 3306
socket = /data/mysql/3306/mysql.sock[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data
port = 3306
socket = /data/mysql/3306/mysql.sock
log-error = /data/mysql/3306/mysql_error.log
pid-file = /data/mysql/3306/mysql.pid
log-bin = /data/mysql/3306/binlog/binlogskip-host-cache
skip-name-resolve
# Independent table space
innodb_file_per_table = 1
# Memory pool
innodb_buffer_pool_size = 2G
innodb_flush_log_at_trx_commit = 1innodb_flush_method=O_DIRECT
[mysqld_safe]
Initialize the database
mysqld --defaults-file=/data/mysql/3306/my.cnf --initialize --user=mysql
#There will be a password in the log
grep "password" /data/mysql/3306/mysql_error.log
C9O3+1&c671S
#Start the database
systemctl start mysqld
Mysql basic operation
#第一次登陆需要修改密码
mysql -uroot -p -S mysql.sock
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
# 创建用户 5.6/5.7 中直接grant 带账号以及授权已无法使用
mysql> create user root@'10.10.10.%' identified by '123456';
mysql> grant all on *.* to root@'10.10.10.%';
#连接数据库
mysql -uroot -p -S mysql.sock
mysql -uroot -p -hxxx -Pxxx