文章目录
Linux安装包方式安装mysql
1. 官网下载对应版本的mysql
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
我下载的版本:mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
2. 查看安装的mysql
[root@test local]# rpm -qa |grep -i mysql
mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
mysql57-community-release-el7-11.noarch
mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
[root@test local]#
3. 卸载并查看是否还有相关信息
[root@test local]# yum remove mysql*
依赖关系解决。
============================================================================================================================================================================================================================================================================
软件包 架构 版本 仓库 大小
============================================================================================================================================================================================================================================================================
移除:
mysql x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 @appstream 62 M
mysql-common x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 @appstream 584 k
mysql-errmsg x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 @appstream 8.2 M
mysql-server x86_64 8.0.21-1.module_el8.2.0+493+63b41e36 @appstream 108 M
mysql57-community-release noarch el7-11 @@commandline 31 k
清除未被使用的依赖关系:
mariadb-connector-c-config noarch 3.1.11-2.el8_3 @appstream 497
mecab x86_64 0.996-1.module_el8.2.0+493+63b41e36.9 @appstream 2.1 M
protobuf-lite x86_64 3.5.0-13.el8 @appstream 450 k
事务概要
============================================================================================================================================================================================================================================================================
移除 8 软件包
将会释放空间:182 M
确定吗?[y/N]: y
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
运行脚本: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 1/1
运行脚本: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 1/8
删除 : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 1/8
运行脚本: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 1/8
删除 : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 2/8
删除 : mysql57-community-release-el7-11.noarch 3/8
删除 : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 4/8
删除 : mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 5/8
删除 : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 6/8
删除 : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 7/8
运行脚本: mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 7/8
删除 : protobuf-lite-3.5.0-13.el8.x86_64 8/8
运行脚本: protobuf-lite-3.5.0-13.el8.x86_64 8/8
验证 : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 1/8
验证 : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 2/8
验证 : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 3/8
验证 : mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 4/8
验证 : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 5/8
验证 : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 6/8
验证 : mysql57-community-release-el7-11.noarch 7/8
验证 : protobuf-lite-3.5.0-13.el8.x86_64 8/8
Installed products updated.
已移除:
mariadb-connector-c-config-3.1.11-2.el8_3.noarch mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64 mysql-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 mysql-common-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64
mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64 mysql57-community-release-el7-11.noarch protobuf-lite-3.5.0-13.el8.x86_64
完毕!
[root@test local]# rpm -qa |grep -i mysql
[root@test local]#
4. 上传下载的mysql包并解压,然后重命名
[root@test mysql]# tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
[root@test mysql]# mv mysql-5.7.39-linux-glibc2.12-x86_64 mysql-5.7.39
5. 添加系统mysql组和mysql用户
检查mysql组和用户是否存在,如无创建
[root@test mysql]# cat /etc/group | grep mysql
mysql:x:27:
[root@test mysql]#
[root@test mysql]# cat /etc/passwd | grep mysql
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin
[root@test mysql]#
如无,执行添加命令:
groupadd mysql
useradd -r -g mysql mysql
6. 安装数据库
- 创建data目录
[root@test mysql-5.7.39]# mkdir data
- 将/usr/local/mysql/mysql-5.7.39的所有者及所属组改为mysql
[root@test mysql-5.7.39]# chown -R mysql.mysql /usr/local/mysql/mysql-5.7.39
- 在/usr/local/mysql/mysql-5.7.39/support-files目录下创建my_default.cnf
[root@test mysql-5.7.39]# cd support-files/
[root@test support-files]# vim my_default.cnf
-
添加内容
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql/mysql-5.7.39
datadir = /usr/local/mysql/mysql-5.7.39/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /usr/local/mysql/mysql-5.7.39/data/mysqld.log
pid-file = /usr/local/mysql/mysql-5.7.39/data/mysqld.pid -
拷贝,如果提示是否覆盖,y
[root@test support-files]# cp my_default.cnf /etc/my.cnf
cp:是否覆盖'/etc/my.cnf'? y
[root@test support-files]#
- 初始化 mysqld
[root@test support-files]# cd /usr/local/mysql/mysql-5.7.39/
[root@test mysql-5.7.39]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.39/ --datadir=/usr/local/mysql/mysql-5.7.39/data/
[root@test mysql-5.7.39]#
- 初始化完成之后,查看日志
[root@test mysql-5.7.39]# cd /usr/local/mysql/mysql-5.7.39/data/
[root@test data]# ll
总用量 110664
-rw-r-----. 1 mysql mysql 56 7月 28 17:12 auto.cnf
-rw-------. 1 mysql mysql 1680 7月 28 17:12 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 7月 28 17:12 ca.pem
-rw-r--r--. 1 mysql mysql 1112 7月 28 17:12 client-cert.pem
-rw-------. 1 mysql mysql 1676 7月 28 17:12 client-key.pem
-rw-r-----. 1 mysql mysql 436 7月 28 17:12 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 7月 28 17:12 ibdata1
-rw-r-----. 1 mysql mysql 50331648 7月 28 17:12 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 7月 28 17:12 ib_logfile1
drwxr-x---. 2 mysql mysql 4096 7月 28 17:12 mysql
-rw-r-----. 1 mysql mysql 1400 7月 28 17:12 mysqld.log
drwxr-x---. 2 mysql mysql 8192 7月 28 17:12 performance_schema
-rw-------. 1 mysql mysql 1676 7月 28 17:12 private_key.pem
-rw-r--r--. 1 mysql mysql 452 7月 28 17:12 public_key.pem
-rw-r--r--. 1 mysql mysql 1112 7月 28 17:12 server-cert.pem
-rw-------. 1 mysql mysql 1680 7月 28 17:12 server-key.pem
drwxr-x---. 2 mysql mysql 8192 7月 28 17:12 sys
[root@test data]# tail -500f mysqld.log
2022-07-28T09:12:45.811698Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-28T09:12:45.830931Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2022-07-28T09:12:45.830941Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2022-07-28T09:12:46.559623Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T09:12:46.725667Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-28T09:12:46.795963Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 721e6ebb-0e55-11ed-b2f0-000c29af01fd.
2022-07-28T09:12:46.798024Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-28T09:12:47.244202Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T09:12:47.244220Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-28T09:12:47.244736Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-28T09:12:47.438518Z 1 [Note] A temporary password is generated for root@localhost: nNf0/lMm_Eqy
-
初始密码:
2022-07-28T09:12:47.438518Z 1 [Note] A temporary password is generated for root@localhost: nNf0/lMm_Eqy -
把启动脚本放到开机初始化目录
[root@test mysql-5.7.39]# cp support-files/mysql.server /etc/init.d/mysql
- 启动mysql服务
service mysql start
- 登录mysql
[root@test lib64]# mysql -uroot -p
Enter password:
- 修改密码
mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
- 添加远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
- 重启mysql生效
service mysql stop 关闭mysql
service mysql start 开启mysql
service mysql restart 重启mysql
[root@test lib64]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@test lib64]#
7. 遇到的问题以及解决方案
- 安装完成登录mysql出现如下情况:
[root@test mysql-5.7.39]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
- 解决方案:
[root@test lib64]# yum install libncurses.so.5
- 安装完成后再次登录:
[root@test lib64]# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
- 解决方案:
[root@test lib64]# ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
- 再次登录,问题解决
[root@test lib64]# mysql -uroot -p
Enter password: