mysql-二进制安装方式
目录
1. 安装组件即依赖包
2. 创建用户
3. 关闭防火墙
4. 解压mysql二进制源码包
5. 创建文件夹并赋予权限
6. 编译安装mysql,安装完成最后面,会有一串英文,那是登录数据库的密码
7. 设置配置文件
8. 将mysql添加进环境变量
9. 复制文件并赋予权限
10. 编辑生成mysqld.service服务文件
11. 开启mysql
12. 登录到mysql并修改密码
1. 安装组件即依赖包
yum install -y gcc gcc-c++ net-tools lrzsz libaio
2. 创建用户
useradd -M -s /sbin/nologin mysql
3. 关闭防火墙
systemctl stop firewalld
setenforce 0
4. 解压mysql二进制源码包
tar zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
5. 创建文件夹并赋予权限
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/d
chown -R mysql.mysql /usr/local/mysql/data/
cd /usr/local/mysql/bin/
6. 编译安装mysql,安装完成最后面,会有一串英文,那是登录数据库的密码
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data –initialize
root@localhost:这一串后面就是密码
h.uuplceh1Ir //这是我的密码
7. 设置配置文件
vim /etc/my.cnf
[client]
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
socket=/usr/local/mysql/data/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=2048
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
8. 将mysql添加进环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
. /etc/profile
9. 复制文件并赋予权限
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
10. 编辑生成mysqld.service服务文件
vim /lib/systemd/system/mysqld.service
[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/mysqld start
ExecReload=/etc/rc.d/init.d/mysqld restart
ExecStop=/etc/rc.d/init.d/mysqld stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
11. 开启mysql
systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld
netstat -nultp | grep 3306
12. 登录到mysql并修改密码
mysql -u root -ph.uuplceh1Ir
mysqladmin -u root -p'h.uuplceh1Ir' password 'ABCabc-123'