CentOS7下安装mysql免安装版(mysql-5-7-24-linux-glibc2-12-x86_64-tar-gz)

1.从mysql官网下载二进制安装包(https://dev.mysql.com/downloads/mysql/
image

2.检查是否已经安装了mysql或者是MariaDB,如果已经安装,则先把安装的卸载

[root@localhost software]# rpm -qa | grep mysql
[root@localhost software]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost software]# yum -y remove mariadb-libs-5.5.56-2.el7.x86_64
3.通过winSCP或者是Xftp等工具将安装包上传到CentOS上,并解压
[root@localhost software]# ll
总用量 629816
drwxr-xr-x. 9 root root       129 12月 25 16:49 mysql-5.7.24-linux-glibc2.12-x86_64
-rw-r--r--. 1 root root 644930593 12月 24 17:15 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost software]# 
4.重命名mysql安装目录
[root@localhost software]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
[root@localhost software]# ll
总用量 629816
drwxr-xr-x. 9 root root       129 12月 25 16:49 mysql
-rw-r--r--. 1 root root 644930593 12月 24 17:15 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost software]# 
5.添加新的用户组和新的用户,用来管理mysql,提高安全性(非必要的,不过mysql官网安装步骤推荐这样做,这个步骤可以省略)
[root@localhost software]# groupadd mysql
[root@localhost software]# useradd -r -g mysql -s /bin/false mysql
[root@localhost software]# 
6.新建mysql的data目录
[root@localhost software]# cd mysql
[root@localhost mysql]# mkdir data
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x.  2 root root   4096 12月 25 16:49 bin
-rw-r--r--.  1 7161 31415 17987 10月  4 13:48 COPYING
drwxr-xr-x.  2 root root      6 12月 25 16:57 data
drwxr-xr-x.  2 root root     55 12月 25 16:49 docs
drwxr-xr-x.  3 root root   4096 12月 25 16:48 include
drwxr-xr-x.  5 root root    230 12月 25 16:49 lib
drwxr-xr-x.  4 root root     30 12月 25 16:49 man
-rw-r--r--.  1 7161 31415  2478 10月  4 13:48 README
drwxr-xr-x. 28 root root   4096 12月 25 16:49 share
drwxr-xr-x.  2 root root     90 12月 25 16:49 support-files
[root@localhost mysql]#
7.修改mysql目录用户为刚刚新建的mysql组中的mysql用户
[root@localhost mysql]# chown -R mysql:mysql ./
8.初始化安装mysql数据库
[root@localhost mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/software/mysql --datadir=/usr/local/software/mysql/data --initialize
2018-12-25T09:00:17.116437Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-25T09:00:21.961838Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-25T09:00:22.747386Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-25T09:00:22.860663Z 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: 8324a8be-0823-11e9-b13d-000c29ca91c6.
2018-12-25T09:00:22.862806Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-25T09:00:22.867377Z 1 [Note] A temporary password is generated for root@localhost: Q&ZsMY#sV3du
[root@localhost mysql]#
9.修改my.cnf配置文件,通过mysql官网可以知道,从版本5.7.18开始,mysql免安装版二进制包中就不包含该文件了,即不需要my.cnf文件也可以正常运行;my.cnf文件中配置的选项会在命令行启动mysql的时候作为参数进行启动,为了后面搭建mysql主从环境方便,下面可以添加了一个简单的my.cnf文件作为实例(如果只是单纯的搭建一个mysql实例,可以直接忽略此步骤),使用vim /etc/my.cnf命令,如果在该目录上不存在则会新建
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/software/mysql
datadir=/usr/local/software/mysql/data
socket=/usr/local/software/mysql/mysql.sock
#设置忽略大小写(简单来说就是sql语句是否严格),默认库名表名保存为小写, 不区分大小写
lower_case_table_names = 1
# 开启ip绑定
bind-address = 0.0.0.0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/software/mysql/data/mysqld.pid
#指定客户端连接mysql时的socket通信文件路径
[client]
socket=/usr/local/software/mysql/mysql.sock
default-character-set=utf8
10.将mysql添加至开机启动
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# 

修改mysqld,使用vim /etc/init.d/mysqld 命令 修改以下代码部分
image
basedir=/usr/local/software/mysql
datadir=/usr/local/software/mysql/data

设置开机启动

[root@localhost mysql]# chkconfig --add mysqld
11.到这一步,mysql已经算是安装完毕了,接下来使用以下命令启动mysql
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/software/mysql/data/localhost.localdomain.err'.
. SUCCESS! 
[root@localhost mysql]#
12.为了可以在任意目录上都可以使用mysql命令登录mysql,将mysql安装目录配置到环境变量中,在/etc/profile文件的末尾添加以下代码
image
export PATH=$PATH:/usr/local/software/mysql/bin

使配置文件的配置立即生效

[root@localhost mysql]# source /etc/profile
13.重启mysql服务,并且使用mysql的root用户登录mysql,密码在第8步最后一行有
[root@localhost mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@localhost mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
14.修改root用户的密码为root,并且刷新
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
15.此时mysql数据库只能在本机上使用mysql命令进行登录,还无法使用navicat等数据库可视化工具进行远程登录,下面设置允许root用户远程连接数据库
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 user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost mysql]# 

为了方便试验,此处已事先使用 systemctl stop firewalld 命令将防火墙关闭,在实际使用中,只需要开放数据库运行的3306端口即可,结果如下:
image
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 221,635评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,543评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 168,083评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,640评论 1 296
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,640评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,262评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,833评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,736评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,280评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,369评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,503评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,185评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,870评论 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,340评论 0 24
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,460评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,909评论 3 376
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,512评论 2 359