mysql安装development_mysql 安装

本文详细介绍了如何在Linux环境下安装MySQL 5.7.16,包括配置环境变量、创建用户和组、初始化数据库、解决启动问题以及设置和修改root密码。此外,还展示了如何为Hive创建新用户和数据库。
摘要由CSDN通过智能技术生成

这里使用的mysql是 mysql-5.7.16

将下载下来的mysql 安装tar包下载解压这就不用多说了,

c65c7fa38fe8b75d7c8c247f839d434c.png

ps:(mysql-5.7.16-linux-glibc2.5-x86_64 这名字太长了,我把他改为mysql-5.7.16)

92670e5855520a0d7815edb25a763da6.png

首先

(1)配置环境变量

############mysql#############

export PATH=$PATH:/usr/local/development/mysql/mysql-5.7.16/bin

(2)新增mysql的用户和组

[root@node1 development]# groupadd mysql

[root@node1 development]# useradd -r -g mysql mysql

//修改mysql的目录权限

[root@node1 development]# chown -R mysql mysql /usr/local/development/mysql/mysql-5.7.16/

(3)修改mysql安装目录中的   support-files/mysql.server 文件,设置mysql的安装目录 和 mysql的数据存储目录

# If you want to affect other MySQL variables, you should make your changes

# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.

//mysql的安装目录

basedir=/usr/local/development/mysql/mysql-5.7.16

//mysql的数据存储目录

datadir=/usr/local/development/mysql/mysqlData

(4)初始化数据库

[root@node1 bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/development/mysql/mysql-5.7.16 --datadir=/usr/local/development/mysql/mysqlData

2017-06-05 17:44:50 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

2017-06-05 17:44:55 [WARNING] The bootstrap log isn't empty:

2017-06-05 17:44:55 [WARNING] 2017-06-05T09:44:51.057443Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

2017-06-05T09:44:51.075095Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2017-06-05T09:44:51.075137Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

我们的MySQL存储目录已经生成数据了

e422bbb9735a25d147d35aff7cc0d1f9.png

(5)启动MySQL(发现报错)

[root@node1 support-files]# ./mysql.server start

Starting MySQL.touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory

/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 169: /var/log/mariadb/mariadb.log: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory

ERROR! The server quit without updating PID file (/usr/local/development/mysql/mysqlData/node1.pid).

我们确实是没有/var/log/mariadb/mariadb.log 这个目录,这个是因为你没有指定他的配置文件的话,他会默认找到/etc/my.cnf 这个配置文件,因为我们修改了mysql的数据存储目录。

将/etc/my.cnf 删掉,再次启动

[root@node1 support-files]# rm -f /etc/my.cnf

[root@node1 support-files]# ./mysql.server start

Starting MySQL.. SUCCESS!

(6)查询MySQL自动生成的root密码

[root@node1 support-files]# more /root/.mysql_secret

# Password set for user 'root@localhost' at 2017-06-05 17:44:50

N5*gFyur1LbC //这里就是

(7)在bin目录下 登录MySQL(将自动生成的密码粘贴上去即可)

[root@node1 bin]# ./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.16

Copyright (c) 2000, 2016, 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.

(8)修改MySQL的root密码(你肯定不想使用自动生成的那个密码吧)

mysql> set password=password('mysql123');//设置密码

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> alter user 'root'@'localhost' password expire never//将密码应用于root用户

-> ;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges//刷新权限的列表

-> ;

Query OK, 0 rows affected (0.00 sec)

mysql> exit//退出

Bye

重新登录,试一试刚才修改的密码是否生效,当然你们是看不见输入密码的,我这里已经生效了

256b5cea70aa2f25b69d3c840ec783d5.png

上面是MySQL的搭建过程,我是使用MySQL来存储hive的元数据,而MySQL不允许使用root用户远程登录,所以我新建hive用户

mysql> create user 'hive'@'%' identified by 'hive123';//创建用户名和密码

Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'hive'@'%';//赋予hive用户所有权限,'%'表示任何地址都可以通过hive用户连接mysql,如果你想限制可以加入你的ip

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;//刷新权限列表

Query OK, 0 rows affected (0.00 sec)

mysql> create database hivedb;//创建数据库

Query OK, 1 row affected (0.00 sec)

查看创建的数据库

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| hivedb |

| mysql |

| performance_schema |

| sys |

+--------------------+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值