2.5Mysql

作者: 王子也寂寞 | 来源:发表于2017-10-30 14:34 被阅读0次

一.Linux安装:

  • 通过rpm -qa| grep mysql-server 命令检查是否已经安装了mysql-server
  • 执行sudo yum -y install mysql-server来安装
  • 默认配置文件在/etc/my.cnf中

二.配置

1.字符集配置

  • 1.vim /etc/my.cnf
  • 2.添加配置,在[mysqld]节点下添加:
    default-character=utf8
    charactor-set-server=utf8
  • 3.保存退出

三.自启动配置

  • 1.执行chkconfig mysqld on
  • 2.执行chkconfig --list mysqld查看(如果2-5位启用on状态即ok)
  • 3.防火墙配置
    1.sudo vim /etc/sysconfig/iptables
    2.添加3306端口
    3.然后保存退出,重启防火墙

四.服务启动

  • 1.启动mysqld服务service mysqld start或者/etc/rc.d/init.d/mysqld start
  • 2.执行mysql -u root 登录MySql服务器

五.MySQL通用配置

  • 1.查看当前mysql的用户
    select user,host,password from mysql.user
  • 2.修改root密码
    set password for root@localhost=password('yourpassword');
    set password for root@127.0.0.1=password('yourpassword');
  • 3.退出mysql
    1. 重新登录mysql输入mysql -u root -p

六.安全配置

  • 1.查看是否有匿名用户:
    select user,host from mysql.user;
  • 2.删除匿名用户:
    delete from mysql.user where user='';
  • 3.再次查看
    select user,host from mysql.user;
  • 4.刷新,使以上配置生效:
    flush privileges;

七.插入mysql新用户

  • 1.insert into mysql.user(Host,User,Password) values ("localhost","yourusername",password("yourpassword"));
  • 2.使操作生效
    flush privileges;

八.创建新的database

CREATE DATABASE `first_pro` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

九.用户赋予所有权限

  • 1.给本地用户:
    grant all privileges on first_pro.* to yourusername@localhost identified by 'yourpassword';
  • 2.外网用户:
    grant all privileges on first_pro.* to yourusername@'%' identified by 'yourpassword';
  • 3.给个别权限:
    grant select,insert,update on first_pro.* to yourusername@'192.111.111.111' identified by 'yourpassword';

注意所有操作后,要刷新

flush privileges;

相关文章

  • 2.5Mysql

    一.Linux安装: 通过rpm -qa| grep mysql-server 命令检查是否已经安装了mysql-...

网友评论

      本文标题:2.5Mysql

      本文链接:https://www.haomeiwen.com/subject/xubppxtx.html