centos7下mysql 8.0.13版本安装

在centos7下采用绿色版安装mysql8.0.13版本

1.下载安装包

到https://dev.mysql.com/downloads/mysql/下选择社区版(Community),然后下滑,选择通用linux版,下载64位的压缩包。


我下载的是第一个链接。安装时先要进行xz解压缩。由于本人电脑为win10系统,centos就装到了VM里,上传centos7里(rz,ftp均可)的tmp目录(省的忘记)。

解压缩mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz,

xz -d mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar。


等tar完成, 将解压后的文件夹拷贝到/usr/local/并重命名为mysql

mv -f mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local/mysql


查看系统是否有libaio包,如果没有无法运行mysql数据库

rpm -qa | grep libaio

libaio-0.3.107-10.el6.x86_64  //表示已经安装


2.建立mysql用户和用户组:

  useradd -s /sbin/nologin -M mysql

修改/usr/local/mysql文件夹的属主和属组为mysql

  chown -R mysql:mysql mysql


3.初始化数据库

启动/usr/local/mysql/bin/目录下的mysqld

./mysqld --initialize --user=mysql

注意其中一句,这是mysql数据库自动生成的临时root密码,一定要记录下来********A temporary password is generated for root@localhost: +&)iV1&tA-pw


4.配置数据库

创建  /usr/local/mysql/support-files/my-default.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

  # These are commonly set, remove the # and set as required.

    basedir = /usr/local/mysql   

  #mysql数据库文件夹所在位置

    datadir = /var/lib/mysql

  #mysql数据库的数据文件所在位置

  # port = .....

  # server_id = .....

    socket = /var/lib/mysql/mysql.sock

  #mysql sock位置

  # 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

    character-set-server=utf8

  #修改mysql服务器默认的字符集

  #此句不是必须

  sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

  [client]

  socket = /var/lib/mysql/mysql.sock

  default-character-set=utf8


保存退出,然后复制到/etc/my.cnf

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf


5.启动并测试数据库

启动数据库

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

 service mysqld start


连接测试数据库

 cd /usr/local/mysql/bin

  ./mysql -u root -p

输入保存的临时密码,进入mysql后先修改root的密码,否则大部分操作都无法进行。修改密码格式如下:

ALTER USER 'username'@'连接的数据库' IDENTIFIED BY 'newpas'.

eg:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

完成!!


附录:

非必要配置

修改环境变量和ld.so.conf

  将含有mysql命令的目录添加到环境变量

  vim  /etc/profile

  PATH=/usr/local/mysql/bin:$PATH

  export PATH

  将mysql目录下的lib目录添加到ld.so.conf文件

  vim /etc/ld.so.conf

  include /usr/local/mysql/lib/

  保存退出后输入

  ldconfig

你可能感兴趣的:(centos7下mysql 8.0.13版本安装)