一:规划目录
yum install -y libaio #安装依赖
tar zxf /root/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ #需要事先下载好二进制包
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/ /usr/local/mysql
echo "export PATH=$PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
useradd mysql;echo 123456|passwd --stdin mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
chmod -R 755 /data/mysql
二:修改配置文件
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character_set_server=utf8
init_connect='SET NAMES utf8'
lower_case_table_names=1
# 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
[mysqld_safe]
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
# include all files from the config directory
!includedir /etc/my.cnf.d
三:开始二进制编译并启动
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --initialize-insecure
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysql start
netstat -lntup|grep 3306
四:设置并初始化数据库
mysql -uroot -S /data/mysql/mysql.sock
ALTER USER 'root'@'localhost' IDENTIFIED BY 'passwd';
grant all privileges on *.* to root@'%' identified by 'passwd' with grant option;
flush privileges;
##################yum安装mysql###########################
rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum install mysql-community-server -y
#创建数据存储目录
mkdir /opt/mysqldate
#先更改配置文件/etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/opt/mysqldate
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
lower_case_table_names=1
pid-file=/var/run/mysqld/mysqld.pid
character_set_server=utf8
init_connect='SET NAMES utf8'
systemctl start mysqld && systemctl enable mysqld
#初始化更改密码
mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
#更改密码强度并设置密码
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;
#登录
mysql -uroot -p123456
##########################mysqldump########################
#所有库一键备份
mysqldump -uroot -p'passwd' -h192.168.100.10 -P3306 --single-transaction -R --triggers -A > /root/sso.sql
#一键导入数据,恢复默认自动创建数据库
mysql -uroot -p'passwd' </root/sso.sql
#单库或多库备份
mysqldump -uroot -p'passwd' -h127.0.0.1 -P3306 --single-transaction -R --triggers -B bsm > /app/bsm.sql
#恢复默认自动创建数据库
mysql -uroot -p'passwd' < /app/bsm.sql