一.目录概述
1.1 概览
1.2 下载地址
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
1.2 文档说明
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
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官网下载地址:https://mirrors.tuna.tsinghua.edu.cn/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 添加新用户组(根据个人需要使用,本次安装没涉及)
添加用户组,将root权限赋值给新建用户组,用专门管理mysql,提高安全
#1.新建组
groupadd mysql
#2.新建用户
useradd -r -g mysql mysql #第一个mysql为用户名,第二个mysql为用户组的名字,表达的意思是:新建一个系统用户mysql并将其归属用户组为mysql
#-g 指定用户所属的组
# -r 创建系统账户
#3.修改mysql目录权限
cd /usr/local/mysql-5.7.26/
chown -R mysql:mysql ./ #第一个mysql为用户名,第二个mysql为用户组的名字,修改权限变为mysql
# chown[选项]...[所有者][:[组]]文件...
2.5. 配置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.6. 配置mysql配置文件
在其他版本的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 [mysqld] # 一般配置选项 basedir = /usr/local/mysql-5.7.26 datadir = /usr/local/mysql-5.7.26/data 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.7 修改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.8 配置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.9 初始化数据库
需要进入到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
执行完毕后会自动生成默认的密码在执行记录中,注意复制出来:上面最后一行标粗加蓝的部分。
2.10 启动服务
[root@meboth-master bin]# service mysql start
Starting MySQL.Logging to '/usr/local/mysql-5.7.26/data/meboth-master.err'.
SUCCESS!
2.11 登录修改密码和远程访问
[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.12 设置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]#
https://www.cnblogs.com/hsbt2333/p/9915616.html
2.13 进入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)