MySQL版本企业选择
5.6版本:5.6.34 5.6.36 5.6.38(Sep 13, 2017) 5.6.40
5.7版本:5.7.20(Sep 13, 2017) 5.7.22 5.7.24 5.7.32
地址:https://downloads.mysql.com/archives/community
一、实验环境
二、实验步骤
1、删除mariadb包
yum -y remove mariadb-libs
2、解压MySQL包
将mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz包拖入root目录
tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.20-linux-glibc2.12-x86_64/ /usr/local/mysql
3、修改环境变量
vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
mysql -V
4、创建用户
useradd -s /sbin/nologin mysql
5、创建数据目录并修改权限
mkdir -p /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data/
6、初始化数据
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7、准备sys-v启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8、创建配置文件
vim /etc/my.cnf
添加:
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
prompt=mysql>
9、启动数据库
service mysqld start
service mysqld stop
10、systemctl管理数据库
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=/etc/my.cnf
LimitNOFILE = 5000
systemctl start mysqld
11、设置root登录MySQL的密码并登录
mysqladmin -u root -p password 123456
mysql -uroot -p123456
12、忘记数据库密码,破解密码
systemctl stop mysqld
跳过权限表,以安全模式启动MySQL
mysqld_safe --skip-grant-tables &
回车
mysql
flush privileges;
grant all on *.* to root@localhost identified by '123.com';
jobs
killall -9 mysqld_safe
systemctl start mysqld
mysql -u root -p123.com
标签:5.7,安装,MySQL,概述,usr,mysql,mysqld,local From: https://blog.csdn.net/2402_88627342/article/details/144832267