美文网首页
新安装MySQL之后设置

新安装MySQL之后设置

作者: 李颖轩_LiYingxuan | 来源:发表于2017-07-28 16:33 被阅读228次

    示例版本是MySQL5.6,操作系统CentOS6.5 - 7.3均可。

    配置MySQL初始设置:

    # 进行一些安全性配置
    [root@localhost ~]# mysql_secure_installation
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MySQL to secure it, we'll need the current
    password for the root user.  If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MySQL
    root user without the proper authorisation.
    
    Set root password? [Y/n] Y   <--是否设置Root密码?
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MySQL installation has an anonymous user, allowing anyone
    to log into MySQL without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y   <--是否删除匿名用户?
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] n   <--是否允许Root远程登录?一般选择Y,不过我为了方便测试,先选N。
     ... skipping.
    
    By default, MySQL comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y   <--是否删除测试数据库?
     - Dropping test database...
    ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
     ... Failed!  Not critical, keep moving...
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y   <--是否刷新权限?
     ... Success!
    
    
    
    
    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    

    配置远程访问

    MySQL不允许远程用户访问主机服务器 1130连接报错:
    ERROR 1130: Host ... is not allowed to connect to this MySQL server
    说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。 需更改 mysql 数据库里的user表里的host项把localhost改称%。

    具体步骤:
    登陆mysql :
    [root@localhost ~]#  mysql -uroot -p
    mysql> use mysql 
    mysql> update user set host='%' where user = 'root';
    ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
    # 有时候会报错,但是不要紧,查看一下成功否。
    mysql> select host from user where user = 'root'; 
    +-------------------------+
    | host                    |
    +-------------------------+
    | %                       |
    | 127.0.0.1               |
    | ::1                     |
    | izm5edi5djftntq1oes7sfz |
    +-------------------------+
    4 rows in set (0.00 sec)
    # host已经有了%这个值,所以没问题了。
    mysql> flush privileges; 
    
    mysql> set global max_allowed_packet = 2*1024*1024*10;
    # 设置最大可存入数据库字段的值长度。
    
    Query OK, 0 rows affected (0.00 sec)
    

    可以远程访问了!

    相关文章

      网友评论

          本文标题:新安装MySQL之后设置

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