Linux下安装MySQL5.7版本
用了四年的笔记本淘汰了,新电脑刚到,迫不及待先开始CentOS7下安装MYSQL
安装如下:
如有遗漏,或者错误,请指教,谢谢!
检查之前是否以安装过mysql,可以使用普通用户sudo 安装,
也可进行root用户安装,本例利用普通用户sudo安装,
[[email protected] ~]$ rpm -qa | grep mysql
[[email protected] ~]$
由于我是新的虚拟机,所以没有,
如果有些朋友出现如下内容:
[[email protected] ~]$ rpm -qa | grep mysql
[[email protected] ~]$mysql-libs-5.1.73-5.el6_6.x86_64
这里的mysql-libs-5.1.73-5.el6_6.x86_64为例子,
如果有类似,之前安装的要卸载掉。
卸载如下:
rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
再次查询:
[[email protected] ~]$ rpm -qa | grep mysql
[[email protected] ~]$
接下来,可以进行安装
我是以命令方式进行安装:
大家也可以去mysql官网下载
https://dev.mysql.com/downloads/mysql/
下载命令:
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
下载过后查看:
[[email protected] ~]$ ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
因为一些配置需要在/usr/local/mysql
解压并移动到/usr/local/mysql/下
在/usr/local/mysql/目录下创建data目录
[[email protected] mysql]$ ls
bin COPYING docs include lib man README share support-files
[[email protected] mysql]$ sudo mkdir data
[[email protected] mysql]$ ls
bin data include man share
COPYING docs lib README support-files
添加mysql用户和组
更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
[[email protected] mysql]$ sudo useradd mysql
useradd:mysql 组已经存在 - 如果您想将此用户加入到该组,请使用 -g 参数。
[[email protected] mysql]$ sudo useradd -g mysql mysql
[[email protected] mysql]$chown -R mysql:mysql /usr/local/mysql
[[email protected] mysql]$chmod -R 755 /usr/local/mysql
编译安装并初始化mysql,初始化输出日志末尾的密码(临时密码需要记住)
首先查询是否有包,如果没有,
安装
yum install libaio-devel.x86_64
yum -y install numactl
rpm -qa|grep libaio
[[email protected] mysql]$cd /usr/local/mysql/bin
[[email protected] mysql]$ ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
执行结果:
[[email protected] bin]$ sudo ./mysqld --initialize --user=mysql --datadir=/usr/openv/mysql/data/ --basedir=/usr/openv/mysql/
2019-12-18T02:55:42.761216Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-18T02:55:43.073823Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-18T02:55:43.111104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-18T02:55:43.166708Z 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: e1b6d072-2141-11ea-b8f2-000c291310cd.
2019-12-18T02:55:43.188741Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-18T02:55:43.189944Z 1 [Note] A temporary password is generated for [email protected]: qyg.Qqqp8jSm
最后为临时密码
编辑配置文件my.cnf,添加配置如下
mysqld]
datadir=/usr/local/mysql/data
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
# include all files from the config directory
#
!includedir /etc/my.cnf.d
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
启动mysql服务器
[[email protected] bin]$/usr/local/mysql/support-files/mysql.server start
如果出现如下提示信息
Starting MySQL... ERROR! The server quit without updating PID file
查看是否存在mysql和mysqld的服务,如果存在,则结束进程,再重新执行启动命令
#查询服务
ps -ef|grep mysql
ps -ef|grep mysqld
#结束进程
kill -9 PID
#启动服务
/usr/local/mysql/support-files/mysql.server start
添加软连接,并重启mysql服务
[[email protected] bin]$ ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[[email protected] bin]$ ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[[email protected] bin]$ service mysql restart
登录mysql,修改密码(把刚才上面的 执行结果:里面最下的密码复制 我的为qyg.Qqqp8jSm)
mysql -u root -p
Enter password:
mysql>set password= password('你的密码');
远程登录:
查询user表,看host和user情况,如下:
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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
所有的用户都是只能本机访问,我们需要把需要远程访问的用户的host改成%,于是我们执行以下语句:
update user set host='%' where user='root';
修改好host之后,我们要让它立即生效,还要执行这样一个语句:
flush privileges;
设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[[email protected] /]$ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[[email protected] /]$ chmod +x /etc/init.d/mysqld
3、添加服务
[[email protected] /]$ chkconfig --add mysqld
4、显示服务列表
[[email protected] /]$ chkconfig --list
上一篇: linux 下安装解压tar.gz 方式安装mysql5.7版
下一篇: MySQL5.7解压版安装
推荐阅读
-
基于Fedora14下自带jdk1.6版本 安装jdk1.7不识别的解决方法
-
解析windows下使用命令的方式安装mysql5.7的方法
-
MySql 5.7.21免安装版本win10下的配置方法
-
win10 下安装mysql服务器社区版本mysql 5.7.22 winx64的图文教程
-
Linux下安装DNS+Sendmail服务的方法
-
linux下改良版本mysqldump来备份MYSQL数据库
-
Linux虚拟机下mysql 5.7安装配置方法图文教程
-
Linux下mysql 8.0.15 安装配置图文教程以及修改密码
-
Linux下Mysql5.6 二进制安装过程
-
Linux下mysql 8.0安装教程