码迷,mamicode.com
首页 > 数据库 > 详细

7、mysql的配置和安装

时间:2018-03-24 12:45:38      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:自动启动   文件   collate   put   yum   soft   utf8   匿名用户   rest   

  1. linux环境下mysql的安装
    1. sudo yum install mysql-server
  2. 修改配置文件
    1. vim /etc/my.cnf
      1. 添加default-character-set = utf8
  3. 设置mysql随系统自动启动
    1.  
    2. 检查设置是否正确
      1. sudo chkconfig --list mysqld
        1. mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
        2. 2-5都是启动则ok
  4. 启动mysql
    1. sudo service mysqld start
      1. 如果出现错误 MySQL Daemon failed to start. 请参考
        1. http://blog.csdn.net/u012286517/article/details/50436740

    2. 删除匿名用户
      1. select user,host from mysql.user;
        1. +------+--------------------+
        2. | user | host |
        3. +------+--------------------+
        4. | root | 127.0.0.1 |
        5. | | localhost |
        6. | root | localhost |
        7. | | vm\_24\_26\_centos |
        8. | root | vm\_24\_26\_centos |
        9. +------+--------------------+
      2. delete from mysql.user where user=‘‘;
    3. 刷新一下权限
      1. flush privileges;
    4. 在防火墙下面开放3306端口,开放给外网
      1. sudo vim /etc/sysconfig/iptables
        1. #mysql port
        2.   -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
      2. 重启防火墙
        1.  service iptables restart
    5. 重新登录mysql
      1. mysql -u root 
    6. 创建一个非root权限的账户,避免使用root
      1. insert into mysql.user(Host,User,Password)values("localhost","mmall",password("mmall"));
      2. 检查插入是否正确
        1. select user,host from mysql.user;
          1. +-------+--------------------+
          2. | user | host |
          3. +-------+--------------------+
          4. | root | 127.0.0.1 |
          5. | mmall | localhost |
          6. | root | localhost |
          7. | root | vm\_24\_26\_centos |
          8. +-------+--------------------+
    7. 创建一个数据库
      1. create database `mmall` default character set utf8 collate utf8_general_ci;
    8. 查看权限
      1. select * from mysql.user \G
    9. 赋予权限
      1. 切换数据库 use mmall;
      2. grant all privileges on mmall.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
        1. 注意,此语句可能有错误,导致执行下面的权限查询的时候出现授权不起作用的现象,可以改为下面的授权语句。
          1. grant all privileges on *.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
        2. 请参看
          1. https://bbs.csdn.net/topics/330154879
      3. 可以更细化权限为
        1. grant select,delete,create on mmall.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
    10. 重新查看全新
        1. select * from mysql.user \G


    11. 修改root账号的密码
      1. set password for root@localhost=password(‘root‘);
      2. set password for root@127.0.0.1=password(‘root‘);
      3. select user,host,password from mysql.user;
    12. 退出重新登录
      1. 使用密码登录,否则没有权限
  5. win下安装mysql    




7、mysql的配置和安装

标签:自动启动   文件   collate   put   yum   soft   utf8   匿名用户   rest   

原文地址:https://www.cnblogs.com/sunnyangzs/p/8638334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!