千家信息网

CentOS7如何安装mysql5.7解压缩版

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章给大家分享的是有关CentOS7如何安装mysql5.7解压缩版的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1.下载安装包http://dev.mysql.com
千家信息网最后更新 2026年11月03日CentOS7如何安装mysql5.7解压缩版

这篇文章给大家分享的是有关CentOS7如何安装mysql5.7解压缩版的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

1.下载安装包

http://dev.mysql.com/downloads/mysql/#downloads

2.检查库文件是否存在,如有删除。

[root@localhost Desktop]$ rpm -qa | grep mysqlmysql-libs-5.1.52-1.el6_0.1.x86_64[root@localhost ~]$ rpm -e mysql-libs-5.1.52.x86_64 --nodeps[root@localhost ~]$

3.检查mysql组和用户是否存在,如无创建。

[root@localhost ~]$ cat /etc/group | grep mysqlmysql:x:490:[root@localhost ~]$ cat /etc/passwd | grep mysqlmysql:x:496:490::/home/mysql:/bin/bash以上为默认存在的情况,如无,执行添加命令:[root@localhost ~]$groupadd mysql[root@localhost ~]$useradd -r -g mysql mysql//useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

4.解压TAR包,更改所属的组和用户

[root@localhost ~]$ cd /usr/local/[root@localhost local]$ tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar[root@localhost local]$ ls -ltotal 1306432-rwxr--r--. 1 root root 668866560 Jun 1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz[root@localhost local]$ tar xvfz mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz[root@localhost local]$ mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql[root@localhost local]$ ls -ltotal 1306436drwxr-xr-x. 2 root root    4096 Dec 4 2009 bindrwxr-xr-x. 2 root root    4096 Dec 4 2009 etcdrwxr-xr-x. 2 root root    4096 Dec 4 2009 gamesdrwxr-xr-x. 2 root root    4096 Dec 4 2009 includedrwxr-xr-x. 2 root root    4096 Dec 4 2009 libdrwxr-xr-x. 3 root root    4096 Dec 2 14:36 lib64drwxr-xr-x. 2 root root    4096 Dec 4 2009 libexecdrwxr-xr-x. 9 7161 wheel   4096 Mar 28 12:51 mysql-rwxr--r--. 1 root root 668866560 Jun 1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gzdrwxr-xr-x. 2 root root    4096 Dec 4 2009 sbindrwxr-xr-x. 6 root root    4096 Dec 2 14:36 sharedrwxr-xr-x. 2 root root    4096 Dec 4 2009 src[root@localhost local]$ chown -R mysql mysql/[root@localhost local]$ chgrp -R mysql mysql/[root@localhost local]$ cd mysql/

5.安装和初始化数据库

[root@localhost mysql]$ bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/2016-06-01 15:23:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2016-06-01 15:23:30 [WARNING] The bootstrap log isn't empty:2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

如果改变默认安装路径,则需要 1)/etc/my.cnf、/etc/init.d/mysqld中修改 basedir='/apps/mysql' datadir='/apps/mysql/data' 2)创建ln mkdir -p /usr/local/mysql/bin ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

[root@localhost mysql]$[root@localhost mysql]$ cp -a ./support-files/my-default.cnf /etc/my.cnf[root@localhost mysql]$ cp -a ./support-files/mysql.server /etc/init.d/mysqld[root@localhost mysql]$ cd bin/[root@localhost bin]# ./mysqld_safe --user=mysql &[1] 2932[root@localhost bin]# 2016-06-01T22:27:09.708557Z mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.2016-06-01T22:27:09.854913Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data[root@localhost bin]# /etc/init.d/mysqld restartShutting down MySQL..2016-06-01T22:27:50.498694Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended SUCCESS!Starting MySQL. SUCCESS![1]+ Done          ./mysqld_safe --user=mysql[root@localhost bin]$//设置开机启动[root@localhost bin]$ chkconfig --level 35 mysqld on[root@localhost bin]$

6.初始化密码

mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。

[root@localhost bin]$ cat /root/.mysql_secret# Password set for user 'root@localhost' at 2016-06-01 15:23:25,xxxxxR5H9[root@localhost bin]$./mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.12Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> SET PASSWORD = PASSWORD('123456');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

7.添加远程访问权限

mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set host = '%' where user = 'root';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select host, user from user;+-----------+-----------+| host   | user   |+-----------+-----------+| %     | root   || localhost | mysql.sys |+-----------+-----------+//一定要重启才会生效。/etc/init.d/mysqld restart

遇到的问题:

找不到mysql.sock,mysql.sock丢失问题解决方法

连接Mysql时,机器上找不到mysql.sock文件你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。

[root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql2016-06-26 02:47:09 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2016-06-26 02:47:09 [ERROR]  The data directory needs to be specified.

解决:需要新建data目录,指定安装目录(在非默认目录时需要指定,默认路径:/usr/local/mysql,同时需要指定./support-files/mysql.server中的basedir和datadir为相应路径)。

[root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.13/ --datadir=/usr/local/mysql-5.7.13/data/2016-06-26 02:48:47 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2016-06-26 02:49:19 [WARNING] The bootstrap log isn't empty:2016-06-26 02:49:19 [WARNING] 2016-06-26T09:48:50.798592Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-26T09:48:50.898732Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2016-06-26T09:48:50.898778Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

以上报错均因未在mysql.server中指定自定义的路径。

若是还提示已经有data文件了 删除了它,新建即可

感谢各位的阅读!关于"CentOS7如何安装mysql5.7解压缩版"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

用户 路径 目录 内容 密码 文件 更多 服务器 篇文章 系统 问题 服务 检查 登录 不错 实用 中指 参数 同时 命令 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 什么是科技互联网 伟宏互联网科技 广州大一互联网络科技有限公司 互联网科技工作委员会副主任毛军 互联网金融监管科技数据 互联网核心科技是什么 河南真二互联网科技有限公司 互联网科技公司官网 电子科技大学互联网 互联网科技生活的内容 济南和联互联网科技有限公司 博兴的互联网电子科技公司 顶级互联网科技成果有哪些 中国航天科技大学国际工业互联网 长沙茂晟互联网科技有限公司 互联网数据科技专业 互联网金融科技元年 深圳互联网科技的发展 下一代互联网重大应用科技园 西安左小互联网科技有限公司 上海睿民互联网科技有限公司 朗涯互联网科技 老年人脱离互联网科技的作文 科技与互联网哪个更好 互联网公司黑科技创始人 用友工业互联网科技发展 银行科技岗属于互联网吗 产业互联网科技服务公司 济南小医互联网科技有限公司招聘 科技互联网专业工作会议发言稿
0