一.目录概述
1.1 概览
1.2 下载地址
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
1.2 文档说明
MySQL :: MySQL 5.7 Reference Manual :: 2.2 Installing MySQL on Unix/Linux Using Generic Binaries
1.3 查看mysql服务
#启动mysql服务
[root@meboth-master hadoop-2.7.6]# service mysql start
Starting MySQL SUCCESS!
#查看状态
[root@meboth-master hadoop-2.7.6]# service mysql status
SUCCESS! MySQL running (4948)
#关闭mysql服务
[root@meboth-master hadoop-2.7.6]# service mysql stop
二.安装
2.1 说明
本次安装是采用下载tar包,然后解压的方式进行操作的。当然也可以通过yum操作进行安装。
Yum操作安装地址:https://blog.csdn.net/u011066470/article/details/52005722
2.2 上传mysql的tar包
Hive官网下载地址:Index of /apache/hive
2.3 解压,重命名
#解压到/usr/local/
[root@meboth-master bigdatabyjurf]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ |
#部分截图如下:
#重命名
[root@meboth-master local]# mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql-5.7.26
#查看mysql目录结构
[root@meboth-master mysql-5.7.26]# ls -l
total 36
drwxr-xr-x. 2 root root 4096 Jun 5 16:19 bin
-rw-r--r--. 1 7161 31415 17987 Apr 13 21:32 COPYING
drwxr-xr-x. 2 root root 55 Jun 5 16:19 docs
drwxr-xr-x. 3 root root 4096 Jun 5 16:19 include
drwxr-xr-x. 5 root root 230 Jun 5 16:19 lib
drwxr-xr-x. 4 root root 30 Jun 5 16:19 man
-rw-r--r--. 1 7161 31415 2478 Apr 13 21:32 README
drwxr-xr-x. 28 root root 4096 Jun 5 16:19 share
drwxr-xr-x. 2 root root 90 Jun 5 16:19 support-files
[root@meboth-master mysql-5.7.26]#
2.4. 配置mysql服务
在mysql的安装目录下,将mysql/support-files下的mysql.server 复制到 /etc/init.d/下并自定义为mysql
#1.修改内容:
basedir=/usr/local/mysql-5.7.26 datadir=/usr/local/mysql-5.7.26/data |
2.复制文件操作
[root@meboth-master mysql-5.7.26]# cp -r support-files/mysql.server /etc/init.d/mysql
2.5. 配置mysql配置文件
2.5.1 配置my.cnf
在其他版本的mysql 里面 support-files下有默认的配置文件,而5.7.24这个版本没有,需要自己创建,下面提供一份简单基本配置
在/etc/目录下新建my.cnf ,有些可能会提示已经存在,因为默认装的数据库配置文件也在,直接覆盖就行
#1.进入目录
[root@meboth-master support-files]# cd /etc
[root@meboth-master etc]#touch my.cnf
#2.编辑my.cnf
[root@meboth-master etc]# vi my.cnf
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port = 3306
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
# 一般配置选项
basedir = /usr/local/mysql-5.7.29
datadir = /usr/local/mysql-5.7.29/data
log-error=/usr/local/mysql-5.7.29/logs/mysql-log.err
pid-file=/usr/local/mysql-5.7.29/mysqlpid.pid
socket=/var/lib/mysql/mysql.sock
default-time-zone=+08:00
event_scheduler=1
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
explicit_defaults_for_timestamp=true
#部分截图如下:
2.5.2 创建制定日志目录和文件
1.创建pid文件
[root@localhost mysql-5.7.29]# touch mysqlpid.pid
2.创建日志文件
[root@localhost mysql-5.7.29]# mkdir -p logs
[root@localhost mysql-5.7.29]# cd logs
[root@localhost logs]# touch mysql-log.err
2.6 修改mysql安装包的目录权限
[root@meboth-master bin]# useradd mysql
#赋值mysql的安装包的权限
[root@meboth-master mysql-5.7.26]# chown -R mysql:mysql /usr/local/mysql-5.7.26
[root@meboth-master local]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 3 root root 26 Apr 13 13:50 java
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 9 mysql mysql 129 Jun 5 20:14 mysql-5.7.26
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Mar 7 15:36 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
2.7 配置mysql的环境变量
[root@meboth-master etc]# vi /etc/profile
[root@meboth-master etc]# source /etc/profile
#内容:
export MYSQL_HOME=/usr/local/mysql-5.7.26 export PATH=$PATH:$MYSQL_HOME/bin |
2.8 初始化数据库
需要进入到mysql的安装的bin目录下,执行命令:
[root@meboth-master bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.26 --datadir=/usr/local/mysql-5.7.26/data
2019-06-05T12:24:58.933297Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-05T12:24:59.037395Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-05T12:24:59.105339Z 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: ef4671f6-878c-11e9-a0bf-000c294b272d.
2019-06-05T12:24:59.107011Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-05T12:24:59.108737Z 1 [Note] A temporary password is generated for root@localhost: Kqrg:74d6od9
执行完毕后会自动生成默认的密码在执行记录中,注意复制出来:上面最后一行标粗加蓝的部分。
如果出现报错:
解决办法:
离线安装MySQL缺少libaio.so.1文件——并离线安装libaio.so.1_图灵农场的博客-CSDN博客_离线安装libaio
2.9 启动服务
[root@localhost bin]# service mysql start Starting MySQL.Logging to '/usr/local/mysql-5.7.29/data/localhost.localdomain.err'. ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.29/data/localhost.localdomain.pid). |
2.9.1 以创建用户名启动
注意:如果在启动服务,报这样的错误,说明使用的用户不对,要使用初始化数据库时候使用的mysql用户。
[root@meboth-master bin]# su mysql [mysql@meboth-master bin]$ service mysql start Starting MySQL. SUCCESS! [boc@localhost bin]$ |
2.9.2 以root用户启动
用root用户执行mysqld 和mysqld_safe ,如果不加--user=root参数,用root用户启动时会报错的,为了让mysqld_safe能进行执行,需要对mysql.service文件进行一点点修改,在/etc/init.d/mysql中进行修改,大约在266行处理,在执行mysqld_safe 时 我加入了--user=root 参数。修改时,通过vim的搜索“mysqld_safe”找到进行修改。
修改前:
修改后:
通过root进行启动:
[root@localhost logs]# service mysql start Starting MySQL. SUCCESS! [root@localhost logs]# ps -ef|grep mysql root 11588 1 0 07:51 pts/1 00:00:00 /bin/sh /usr/local/mysql-5.7.29/bin/mysqld_safe --user=root --datadir=/usr/local/mysql-5.7.29/data --pid-file=/usr/local/mysql-5.7.29/mysqlpid.pid root 11828 11588 2 07:51 pts/1 00:00:00 /usr/local/mysql-5.7.29/bin/mysqld --basedir=/usr/local/mysql-5.7.29 --datadir=/usr/local/mysql-5.7.29/data --plugin-dir=/usr/local/mysql-5.7.29/lib/plugin --user=root --log-error=/usr/local/mysql-5.7.29/logs/mysql-log.err --pid-file=/usr/local/mysql-5.7.29/mysqlpid.pid --port=3306 root 11865 10309 0 07:52 pts/1 00:00:00 grep --color=auto mysql |
截图如下:
2.10 登录修改密码和远程访问
[root@meboth-master bin]# ./mysql -uroot -p
#输入上面生成的临时密码:Kqrg:74d6od9
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26
Copyright (c) 2000, 2019, 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.
#设置新密码为123
mysql> set password=password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#设置运行远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123'; #123位上面的步骤设置的新密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
#开始使用
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
2.11 设置mysql开启自启动
不设置mysql自启动的话,每次关机重新启动机器,mysql服务是关闭的,启动hive等等一些软件将无法使用。
[root@meboth-master hadoop-2.7.6]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@meboth-master hadoop-2.7.6]# chkconfig --add mysql
[root@meboth-master hadoop-2.7.6]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@meboth-master hadoop-2.7.6]# chkconfig mysql on
[root@meboth-master hadoop-2.7.6]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@meboth-master hadoop-2.7.6]#
Centos 7.5安装 Mysql5.7.24 - 快乐在角落里 - 博客园
2.12 进入mysql的命令行模式
密码为:123
[root@meboth-master ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_jurf |
| hive |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.07 sec)
第三章 简单功能
3.1 新建一张表实现查询
3.1.1 新建一张表
mysql> use db_jurf
Database changed
mysql> create table tb_employee(id int not null primary key,name varchar(255),age int)
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_db_jurf |
+-------------------+
| tb_employee |
+-------------------+
1 row in set (0.00 sec)
mysql> insert into tb_employee values(1,'liming',23);
Query OK, 1 row affected (0.01 sec)
mysql> select * from tb_employee where id=1;
+----+--------+------+
| id | name | age |
+----+--------+------+
| 1 | liming | 23 |
+----+--------+------+
1 row in set (0.00 sec)