CentOS 7 64位系统下,Mysql安装环境搭建

426 阅读2分钟

Mysql安装

  1. 下载安装
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server

在这里插入图片描述 2. 启动服务

service mysqld restart
  1. 设置密码
mysql -u root
set password for 'root'@'localhost'=password('root');
  1. 设置权限
mysql -u root -proot
grant all privileges on *.* to root@'%'identified by 'root';
  1. 检查字符集
show variables like '%character%';
  1. 检测数据库引擎
show engines;
show variables like'storage_engine';

在这里插入图片描述

  1. 创建用户
insert into mysql.user(Host,User,Password) values("%","test",password("1234"));

注意:此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。 此处直接insert,报错: ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

采用下面方式

GRANT USAGE ON *.* test'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
  1. 用户授权 8.1 登录MYSQL(有ROOT权限),这里以ROOT身份登录:
  @>mysql -u root -p
  @>密码

  8.2 首先为用户创建一个数据库(testDB):

  mysql>create database testDB;

  8.3 授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

   mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
   mysql>flush privileges;//刷新系统权限表

  格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; 

  8.4 如果想指定部分权限给一用户,可以这样来写:

  mysql>grant select,update on testDB.* to test@localhost identified by '1234';
  mysql>flush privileges; //刷新系统权限表

  8.5 授权test用户拥有所有数据库的某些权限:  

  mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
 //test用户对所有数据库都有select,delete,update,create,drop 权限。

  //@"%" 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。)  //对localhost授权:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。