mysq搭建

#mysql5.7.24安装步骤
下载:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
tar zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -r -s /sbin/nologin mysql
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql

vim /usr/local/mysql/support-files/mysql.server
#修改
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

vim /etc/my.cnf
#修改
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8

[mysqld]
# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

#初始化数据库,记住初始密码
yum -y install libaio numactl.x86_64
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#启动mysql
/usr/local/mysql/support-files/mysql.server start|stop|restart

#登录mysql
/usr/local/mysql/bin/mysql -uroot -p
密码:之前初始化的密码

#登录后重新设置密码
set password=password('新密码');

#设置远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '访问密码';
flush privileges;

#开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

#设置命令环境变量
# mysql environment
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile

#开机自启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
chkconfig --list

#备份恢复
mysqldump -u root -p --databases ovk_zsk > ovk_zsk_sql
mysql -u root -p ovk_zsk < ovk_zsk_sql

posted @ 2019-04-03 10:24  自在1990  阅读(144)  评论(0编辑  收藏  举报