• Centos 7 下载安装 mysql server 5.6 (亲测可用)


     
    [root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    [root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
    [root@localhost ~]# yum install mysql-community-server

    (1)首先启动MySQL

    [root@localhost ~]# systemctl start  mysqld.service

    (2)查看MySQL运行状态:

    [root@localhost ~]# systemctl status mysqld.service
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: To do so, start the server, then issue the following commands:
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: /usr/bin/mysqladmin -u root password 'new-password'
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: /usr/bin/mysqladmin -u root -h node3 password 'new-password'
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: Alternatively you can run:
    Feb 05 16:35:28 node3 mysql-systemd-start[36267]: /usr/bin/mysql_secure_installation

     修改root的密码
    /usr/bin/mysqladmin -u root password 'new-password'

    配置

    /usr/bin/mysql_secure_installation

    Enter current password for root (enter for none):  # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车

    Set root password? [Y/n]  # 设置密码,y

    New password:  # 新密码
    Re-enter new password:  # 再次输入密码

    Remove anonymous users? [Y/n]  # 移除匿名用户, Y

    Disallow root login remotely? [Y/n]  # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录

    Remove test database and access to it? [Y/n]  # 删除test数据库,Y:删除。n:不删除,数据库中会有一个test数据库,一般不需要

    Reload privilege tables now? [Y/n]  # 重新加载权限表,Y。或者重启服务也许
     
     (4)如下命令登录数据库:

    [root@localhost ~]# mysql -u root -p

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    创建新数据库

     MariaDB [mysql]> CREATE DATABASE mytestdb  CHARACTER SET 'utf8';

    创建新用户和授权
    MariaDB [mysql]> use mytestdb;
    MariaDB [mysql]> grant all on mytestdb.* to 'myuser'@'%' identified by 'mypass';
    MariaDB [mysql]> flush privileges;

    MariaDB [mysql]> select host, user from user;
    +-----------+--------+
    | host      | user   |
    +-----------+--------+
    | %         | myuser |
    | 127.0.0.1 | root   |
    | ::1       | root   |
    | localhost | root   |
    | node3     | root   |
    +-----------+--------+


     
    4 、开启防火墙端口,CentOS为firewalld添加开放端口3306,具体是什么参考如下:

    [root@aaa]# firewall-cmd --query-port=3306/tcp  # 查看3306端口是否开启
    no
    [root@aaa]# firewall-cmd --zone=public --add-port=3306/tcp --permanent  # 开启3306端口
    success
    [root@aaa]# firewall-cmd --reload  # 重启防火墙
    success
    [root@aaa]# firewall-cmd --query-port=3306/tcp  # 查看3306端口是否开启
    yes 

     


    5 、更改mysql的语言

    首先重新登录mysql,然后输入status:
    MariaDB [mysql]> status
     
     可以看到,不是utf-8,修改为utf8即可。

    因此我们先退出mysql,然后再到/etc目录下的my.cnf文件下修改一下文件内容
     

     设置字符集为utf-8

    vi /etc/my.cnf  文件

    在  [mysqld]  标签下添加

    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake
     


     到此CentOS7安装Mysql 完毕。

     重启:

    systemctl restart  mysqld.service

  • 相关阅读:
    Codeforces Round #650 (Div. 3)
    C. Count Triangles
    A National Pandemic (思维 + 树链剖分模版)
    扫描线专题
    扫描线模版
    莫队模版
    JS设计模式 -- 4种创建型模式
    滑动窗口的最大值 -- 单调队列
    JS链表实现栈和队列
    js数组扁平化的几种实现方式
  • 原文地址:https://www.cnblogs.com/emanlee/p/14378569.html
Copyright © 2020-2023  润新知