linux上mysql安装与创建用户赋予权限(安装包安装)

安装包方式安装MySQL

1、先删除自带mysql

    yum remove mysql-libs   #yum删除MySQLlib

2、上传tar格式安装包(mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar为例)并解压

tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar -C /mysql

3、进入 mysql目录、查看解压文件

mysql-community-client-5.7.19-1.el7.x86_64.rpm           mysql-community-libs-5.7.19-1.el7.x86_64.rpm
mysql-community-common-5.7.19-1.el7.x86_64.rpm           mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-devel-5.7.19-1.el7.x86_64.rpm            mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-5.7.19-1.el7.x86_64.rpm         mysql-community-server-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm  mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm

mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm   mysql-community-test-5.7.19-1.el7.x86_64.rpm

4、执行,命令安装

rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm

rpm -ivh mysql-community-devel-5.7.19-1.el7.x86_64.rpm  (可选)

5、启动MySQL

     启动MySQL:service mysqld start

     或者:systemctl start mysqld.service

6、初次登录

eg1:mysql -hlocalhost -uroot -p12345 -P3306

eg2:mysql -hlocalhost -uroot -p

    然后再输入密码

6-1,、再登录前查看初始密码:

查看root用户的密码:cat /var/log/mysqld.log | grep password

linux上mysql安装与创建用户赋予权限(安装包安装)_第1张图片

7、修改密码(root用户)  (需要重新启动数据库服务)

登录后修改密码:alter user 'root'@'localhost' identified by 'Welcome_1';   

8、创建一个数据库

创建一个新的数据库:create database hive;

9、创建一个新的用户 (名字是hiveowner,密码是:Welcome_1)

 create user 'hiveowner'@'%' identified by 'Welcome_1';

10、给该用户授权

     grant all on hive.* TO 'hiveowner'@'%'; 

     grant all on hive.* TO 'hiveowner'@'localhost' identified by 'Welcome_1';

你可能感兴趣的:(MySQL)