• centos 7.3 服务器环境搭建——MySQL 安装和配置


    centos 7.3 服务器环境搭建——MySQL 安装和配置
    服务器信息如下:
    服务器:阿里云
    系统 centos 7.3 (阿里云该版本最新系统)
    mysql版本:5.7.18 (当前时间最新版本)
    连接服务器工具:xshell
    1、 配置yum源
    更新yum源
    yum update
    下载mysql源安装包
    wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    安装mysql源
    yum localinstall mysql57-community-release-el7-8.noarch.rpm
    检查mysql源是否安装成功
    yum repolist enabled | grep "mysql.*-community.*"
    安装MySQL
    yum install mysql-community-server
    注意:在这过程中会询问的都按y然后回车允许

    2、安装MySQL
    yum install mysql-community-server
    3、启动MySQL
    启动MySQL服务
    systemctl start mysqld
    查看MySQL的启动状态
    systemctl status mysqld
    设置MySQL开机启动
    systemctl enable mysqld
    systemctl daemon-reload
    4、修改root默认密码
    找到root默认密码
    grep 'temporary password' /var/log/mysqld.log
    进入mysql控制台, 输入上述查询到的默认密码
    mysql -uroot -p
    第一次登录必须修改初始密码:(最新mysql要求密码必须包含大小写字母和字符,长度大于等于8个字符)
    alter user root@localhost identified by '连接密码!';
    显示数据库内容
    show databases;
    查看端口号
    show global variables like 'port';
    5、添加远程登录用户
    默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户

    添加远程帐户(密码同上规则)
    GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY '连接密码!' WITH GRANT OPTION;
    立即生效
    flush privileges;
    退出mysql操作
    exit

    总结:
    my.cnf文件:

    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

    [mysqld]

    #skip_grant_tables跳过密码直接登录

    #validate_password=off 跳过密码强度验证(大小写+特殊字符+数字)
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid


    #--------------------------

    #将数据库切换至mysql库
    mysql> USE mysql;
    #修改密码
    mysql> UPDATE user SET authentication_string=PASSWORD(‘数据库连接密码’)WHERE user=’root’;
    #刷新MySQL权限相关的表
    mysql> flush privileges;
    mysql> exit;
    添加远程账户访问:
    grant all privileges on *.* to 'root'@'%%' identified by '数据库连接密码' with grant option;
    立即生效:flush privileges;


    update mysql.user set authentication_string=password('数据库连接密码') where user='root';

    关闭密码验证:my.cnf文件中加入:validate_password=off
    修改密码:
    update user set authentication_string=password("数据库连接密码") where user='root';

  • 相关阅读:
    AOJ 0189 Convenient Location (Floyd)
    AOJ 2170 Marked Ancestor[并查集][离线]
    POJ 1703 Find them, Catch them (并查集)
    复制构造函数 与 赋值函数 的区别(转)
    POJ 2236 Wireless Network (并查集)
    POJ 2010 Moo University
    POJ 3614 Sunscreen (优先队列)
    HTML页面下雪特效
    基于Jquery的XML解析器,返回定制的HTML
    HTML,CSS 无边框桌面窗口
  • 原文地址:https://www.cnblogs.com/doufuyu/p/10855362.html
Copyright © 2020-2023  润新知