centos7.2 安装mysql

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中

    [mysqld]
    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';


---------------------
仅供个人学习之用
转载自原文:https://blog.csdn.net/u013890624/article/details/79653116
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值