热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

centos7.2安装mysql5.7.21

mysql下载地址:https:www.mysql.comdownloads1.进入mysql官网下载页面2.选择mysql数据库3.选择linux版本的

mysql下载地址:https://www.mysql.com/downloads/

1.进入mysql官网下载页面


2.选择mysql数据库



3.选择linux版本的mysql


4.将下载的mysql-5.7.21-linux-glibc2.12-x86_64.tar上传至服务器,我这里是放在home目录

5.解压文件

     [root@VM_0_6_centos home]# tar -xzvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

6.将解压的目录移动至/usr/local/mysql目录

    [root@VM_0_6_centos home]# mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql

7.创建mysql用户组

      [root@VM_0_6_centos local]# groupadd mysql

8.创建一个用户名为mysql的用户并加入mysql用户组

     [root@VM_0_6_centos local]# useradd -r -g mysql mysql

9.进入mysql目录并新建data目录

    [root@VM_0_6_centos local]# cd mysql
    [root@VM_0_6_centos mysql]# mkdir data

10.修改目录权限

    [root@VM_0_6_centos local]# chown -R mysql mysql/

    [root@VM_0_6_centos local]# chgrp -R mysql mysql/

11.进入mysql的bin目录安装和初始化mysql

    [root@VM_0_6_centos local]# cd /usr/local/mysql/bin

    [root@VM_0_6_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/

    如果报./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

    则执行[root@VM_0_6_centos bin]# yum -y install numactl

    命令执行完成后再次执行

    [root@VM_0_6_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/

    2018-03-22T05:52:45.732314Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-03-22T05:52:45.732447Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
    2018-03-22T05:52:46.709894Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2018-03-22T05:52:46.962543Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-03-22T05:52:47.059116Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3f532669-2d95-11e8-93ab-5254009d2e6a.
    2018-03-22T05:52:47.068644Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

    2018-03-22T05:52:47.069069Z 1 [Note] A temporary password is generated for root@localhost: k4lqoR)jpwTc

    如果包以下错误

    2018-03-22T05:52:45.732447Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.

    则执行以下命令

   [root@VM_0_6_centos data]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

   如果包以下错误

    2018-03-22T07:08:58.802194Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

    2018-03-22T07:08:58.802220Z 0 [ERROR] Aborting

    则删除/usr/local/mysql/data目录下的data文件夹,再新建一个data。或者清空data文件夹



12.配置my.cnf

    进入etc目录编辑my.cnf

    [root@VM_0_6_centos bin]#cd /

    [root@VM_0_6_centos /]cd etc

    [root@VM_0_6_centos etc]vim my.cnf

    将以下配置加入到my.cnf中

    [mysql]
    default-character-set=utf8
    port = 3306
     basedir=/usr/local/mysql
     datadir=/usr/local/mysql/data
     max_cOnnections=500
     character-set-server=utf8
     default-storage-engine=INNODB
     lower_case_table_names=1

     max_allowed_packet=20M

13.启动服务

        [root@VM_0_6_centos etc]# cd /usr/local/mysql/support-files

        [root@VM_0_6_centos support-files]# cp mysql.server /etc/init.d/mysql  

        [root@VM_0_6_centos support-files]# chmod +x /etc/init.d/mysql

        [root@VM_0_6_centos bin]# service mysql start

    如果报以下错误

    Starting MySQL.2018-03-22T07:00:17.265252Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.

    ERROR! The server quit without updating PID file (/var/lib/mysql/VM_0_6_centos.pid).

    则执行以下命令

    [root@VM_0_6_centos bin] mkdir /var/log/mariadb 
      [root@VM_0_6_centos bin] touch /var/log/mariadb/mariadb.log 

      [root@VM_0_6_centos bin] chown -R mysql:mysql /var/log/mariadb/

    再次启动服务

    [root@VM_0_6_centos bin]# service mysql start

    Starting MySQL. SUCCESS! 

    出现以上信息说明mysql服务启动成功

14.将mysql服务添加进开机启动项

    [root@VM_0_6_centos support-files]# chkconfig --add mysql 

15.登录数据并修改密码

    进入/usr/local/mysql/bin目录

    [root@VM_0_6_centos bin]# ./mysql -u root -p

    这里的密码是初始化数据库是产生的密码

    登录数据库后,执行以下操作修改root用户密码

    mysql> set password=password("root")

16.设置远程登录权限

    mysql> grant all privileges on *.* to'root' @'%' identified by 'root';

    




    




推荐阅读
author-avatar
涂凌萱_TLX_9s7_140
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有