1、下载安装包
mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
是 MySQL 5.7.33 版本的 Linux 64 位二进制安装包。该文件包含了预编译的 MySQL 服务器、客户端以及一些相关工具,适用于基于 Linux 的操作系统(特别是支持 glibc 2.12 或更高版本的系统)。安装包不依赖于系统的包管理器(如 yum
或 apt
),因此非常适合那些希望手动安装 MySQL 或不希望通过操作系统的默认包管理工具来管理安装的用户。它通常用于在没有 MySQL 官方仓库或特定版本需求的环境中部署 MySQL。
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
1)解压
tar -xvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
2)mariadb
查看是否安装了mariadb
,安装了则卸载
查看:
rpm -qa | grep mariadb
卸载:
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
3)新建mysql文件夹
在/usr/local/
下新建mysql
文件夹,移动至/usr/local/mysql
重命名为mysql-5.7.33
mkdir /usr/local/mysql
mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql/
cd /usr/local/mysql/
mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql-5.7.33
4)添加用户和组
cat /etc/group | grep mysql
groupadd mysql
useradd -r -g mysql mysql
2、安装数据库
1)创建data目录
cd mysql-5.7.33
mkdir data
2)修改属组
将/usr/local/mysql/mysql-5.7.33/
的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql/mysql-5.7.33/
3)创建配置文件
在/usr/local/mysql/mysql-5.7.33/support-files
目录下创建my_default.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** 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. # [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 # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # 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 [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /usr/local/mysql/mysql-5.7.33 datadir = /usr/local/mysql/mysql-5.7.33/data port = 3306 socket = /tmp/mysql.sock character-set-server=utf8 log-error = /usr/local/mysql/mysql-5.7.33/data/mysqld.log pid-file = /usr/local/mysql/mysql-5.7.33/data/mysqld.pid
4)复制移动配置文件
cp my_default.cnf /etc/my.cnf
5)初始化 mysqld
cd mysql-5.7.33/
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.33/ --datadir=/usr/local/mysql/mysql-5.7.33/data/
6)查看临时密码
初始化完成之后,查看日志,记住临时密码
cd data/
cat mysqld.log
3、配置
1)设置开机启动
把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/mysql-5.7.33/bin/my_print_defaults /usr/bin/
chkconfig --add mysqld
chkconfig mysqld on
2)启动mysql
service mysql start
3)修改密码
登录mysql,密码为初始密码
cd /usr/local/mysql/mysql-5.7.33
./bin/mysql -u root -p
密码修改123456
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
4)添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
如果出现错误:ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’
通过:mysql> select user, host from user;
查看是否已存在:
已存在则不用update
,重复则删除host
为%
的,然后再update
。
5)重启mysql生效
service mysql restart