Linux上安装设置mysql 5.7.24

一,准备

1,先查看Linux是32位还是64位

getconf LONG_BIT

如果返回的是32,那么就是32位

如果返回的是64,那么就是64位

2,如果服务器不能联网,就先去官网下载好压缩包,然后上传到服务器

下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

我这里下载的是64位的5.7.24版本的

Linux上安装设置mysql 5.7.24

二,开始安装

1,检查是否已安装过mariadb,若有便删除(linux系统自带的)

[root@localhost /]# rpm -qa | grep mariadb
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.-.el7.centos.x86_64

2,检查是否已安装过mysql,若有便删除(linux系统自带的)

[root@localhost /]# rpm -qa | grep mysql
[root@localhost /]# rpm -e –-nodeps mysql-libs-5.1..x86_64

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

[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd |grep mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql

4,将下载的安装包上传到服务器的/home文件夹下,然后解压

tar -zxvf mysql-5.7.-linux-glibc2.-x86_64.tar.gz

将解压后的文件夹移动到/usr/local下,并将目录名称改为mysql

mv /home/mysql-5.7.-linux-glibc2.-x86_64 /usr/local/mysql

5,在mysql下添加data目录

[root@localhost ~]# mkdir /usr/local/mysql/data

6,更改mysql目录下所有的目录及文件夹所属组合用户

[root@localhost /]# cd /usr/local/
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost local]# chmod -R mysql/

7,编译安装并初始化mysql,记住命令行末尾的密码:

[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
--31T08::.910440Z [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
--31T08::.910635Z [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' con
figuration directive.--31T08::.709286Z [Warning] InnoDB: New log files created, LSN=
--31T08::.767540Z [Warning] InnoDB: Creating foreign key constraint system tables.
--31T08::.892629Z [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: 6e083b8f-8e29-11e7-88b1-
005056b427be.--31T08::.895674Z [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
--31T08::.896645Z [Note] A temporary password is generated for root@localhost: gFamcspKm2+u

8,启动mysql服务

[root@localhost local]# /usr/local/mysql/support-files/mysql.server start

9,做个软连接,重启服务

[root@localhost local]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost local]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

10,做个软链接,将安装目录下的mysql 放在/usr/bin 目录下(这一步我好像没有操作)

[root@localhost local]# ln -s /usr/local/mysql/bin/mysql /usr/bin

11,登录msyql,输入密码(密码为步骤7初始化生成的密码)

[root@localhost local]# mysql -u root -p
Enter password:

12,修改密码并开放远程

msql>alter user 'root'@'localhost' identified by '';
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
mysql>quit

13,编辑my.cnf,添加配置文件,配置内容为

[root@localhost local]# vi /usr/local/mysql/my.cnf
[mysqld]
port =
sql_mode=
transaction_isolation=READ-COMMITTED log_bin_trust_function_creators=
lower_case_table_names=
binlog_format=mixed

14,重启mysql

service mysqld restart

参考:https://www.cnblogs.com/fangts/p/8994851.html

三,遇到的问题

1,查看mysql是否启动的时候service mysql status报错

信息如下:

ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

解决方法如下:

rm /var/lock/subsys/mysql

2,启动mysql的时候service mysql start报错,

错误信息如下:

Starting MySQL...The server quit without updating PID file [失败]lib/mysql/localhost.localdomain.pid)

原因及解决方法:是因为my.cnf配置文件中有一个配置写错了,去掉就可以了

四,创建数据库

CREATE DATABASE `datashare` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

五,导入.sql文件

1,登录mysql

[root@localhost local]# mysql -u root -p
Enter password:

2,选择数据库

mysql>use datashare;

3,导入数据(注意sql文件的路径)

mysql>source /home/datashare.sql;

4,查看数据库

show databases;

查看表

show tables;
上一篇:oracle中实现自增id


下一篇:【BLE】CC2541之加入自己定义任务