美文网首页
CentOS7 安装MySQL5.7

CentOS7 安装MySQL5.7

作者: 热血大桃子 | 来源:发表于2019-02-24 17:39 被阅读0次

    简单记录如何在CentOS7 安装配置MySQL5.7以备以后查用。

    • 安装mysql官网给出的方法安装mysql社区版
    >>> wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    >>> rpm -ivh mysql-community-release-el7-5.noarch.rpm
    # 查看有哪些版本的mysql:
    >>> yum repolist all | grep mysql
    # yum-config-manager 命令修改相应的版本为启用状态最新版本为禁用状态;
    # 根据需要禁用相应版本,这里要安装mysql5.7,所以禁用mysql8
    >>> yum-config-manager --disable mysql80-community
    >>> yum-config-manager --enable mysql57-community
    # 安装mysql server
    >>> yum install mysql-community-server
    
    • 安装成功之后重启mysql服务
    >>> sudo service mysqld restart
    
    • 初次安装mysql是没有密码的,需要我们自己修改密码
    >>> mysql -u root
    
    • 如果告诉你没有登录权限,是因为在安装mysql的时候系统会生成一个标记过期的初始密码,需要管理员更改此密码
    >>> grep "temporary password" /var/log/mysqld.log
    
    • 使用此密码登录mysql
    >>> mysql -u root -p
    >>> show databases;
    >>> use mysql;
    >>> show tables;
    >>> select user,password,host from user;
    # 更新密码
    >>> set password for root@localhost = password('123456')
    # 然后退出重新登录
    >>> exit;
    >>> mysql -u root -p
    
    • 允许以root身份远程登录mysql
    >>> grant all privileges on *.* to root@'%' identified by '123456';
    >>> flush privileges;
    
    • 修改数据库的配置文件(包括进行优化数据库,配置字符集)
    >>> sudo vim /etc/my.cnf
    # 填入如下内容
    [mysqld]
    #
    # 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.
    # 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
    default-storage-engine=INNODB
    #innodb_data_home_dir = /home/mysql/data
    
    # innodb_data_file_path = ibdata1:76M;ibdata2:128M:autoextend
    # innodb_log_group_home_dir = /home/mysql/data
    # innodb_log_arch_dir = /home/mysql/data
    
    # You can set .._buffer_pool_size up to 50 - 80 %  of RAM but beware of setting memory usage too high
    innodb_buffer_pool_size = 64G
    # innodb_additional_mem_pool_size = 16M
    
    innodb_log_file_size = 256M
    innodb_log_buffer_size = 16M
    innodb_flush_log_at_trx_commit = 1
    innodb_flush_method=O_DIRECT
    
    # 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
    port=3306
    character_set_server=utf8mb4
    [client]
    default_character_set=utf8mb4
    
    • 保存退出后,重新启动MySQL
    >>>  sudo systemctl restart mysqld
    # 登录后简单查看字符集编码
    >>> show variables like 'character%';
    

    相关文章

      网友评论

          本文标题:CentOS7 安装MySQL5.7

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