私有化部署--安装MySQL5.7应用
【摘要】 由于mysql 5.7版本以后 support_files文件夹中无 my_default.cnf 文件,所以今天给大家详细描述一下 mysql 5.7版本的安装步骤,本次安装mysql提供两种安装方法。yum安装卸载系统自带MySQL检查服务中是否有自带的mysql,如果有就removeyum list installed|grep mysqlyum -y remove m...
由于mysql 5.7版本以后 support_files文件夹中无 my_default.cnf
yum安装
卸载系统自带MySQL
检查服务中是否有自带的mysql,如果有就remove
yum list installed|grep mysql
yum -y remove mysql-libs.x86_64
下载安装MySQL高版本源
源的下载你可以去官网下载,也可以去清华源下载。个人比较喜欢清华源
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql57-community-release-el7-10.noarch.rpm
yum localinstall mysql57-community-release-el7-10.noarch.rpm
# 检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
安装MySQL
安装
yum install mysql-community-server
# 检查mysql是否安装成功
rpm -qa|grep mysql启动MySQL
systemctl start mysqld
修改MySQL的root的密码
# 查看yum安装MySQL默认密码
grep localhost /var/log/mysqld.log
# 进入MySQL数据库
mysql -uroot -p默认密码
- mysql> set global validate_password_policy=0;
- mysql> set password=password('your passwd');
二进制包部署
下载并解压二进制包
cd /usr/local/src/
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
tar zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
创建用户和所需目录
useradd mysql
touch /var/log/mysqld.log
chmod 777 !$
chown mysql:mysql !$
cd /usr/local/mysql
mkdir data
chmod 777 ../mysql/
chown mysql:mysql !$
修改my.cnf配置文件
vim /etc/my.cnf
# 删除里面的所有内容添加下面的内容
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#不区分大小写
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
配置MySQL服务启动脚本并加入系统变量
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
export PATH=$PATH:/usr/local/mysql/bin
启动MySQL并修改密码
/etc/init.d/mysqld start
# 如果启动的时候出现提示 Starting MySQL.. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
# 执行如下命令
mkdir /var/run/mysqld/
touch /var/run/mysqld/mysqld.pid
chmod 777 /var/run/mysqld/mysqld.pid
chown mysql:mysql !$
/etc/init.d/mysqld start
修改MySQL的root密码
# 查看yum安装MySQL默认密码
grep localhost /var/log/mysqld.log
# 进入MySQL数据库
mysql -uroot -p默认密码
- mysql> set global validate_password_policy=0;
- mysql> set password=password('your passwd');
【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)