Linux下CentOS 7安装mysql8.0.18以及自启动

本次安装的mysql版本是mysql8.0.18,安装包在这里,有需要的小伙伴点击下载,提取码:qbe3。如需其他版本,点击这里前往官网下载对应版本。

一、检查Linux是否安装了mysql

#使用如下命令,如果有的话需要先卸载干净才能够继续下一步安装
rpm -qa|grep -i mysql

#移除系统原来的mysql包,以免影响后续安装
rpm -qa|grep mariadb
rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64
yum remove mariadb-libs-5.5.44-2.el7.centos.x86_64

二、使用安装包传到Linux,我用的工具是Xftp

#使用tar命令解压安装包
tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar

#解压mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz文件
tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

#解压后的文件夹重命名并移动到/usr/local目录下
 mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql
 mv mysql /usr/local

三、开始mysql的配置

cd /usr/local

#添加用户组合用户
groupadd mysql
useradd -f -g mysql mysql

#授权
chown -R mysql:mysql ./

#在/usr/local/mysql下创建data文件夹
mkdir data

#初始化数据库
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

初始化数据库后会得到如下信息,其root@localhost后面的为初始密码,需要记住后面要用

2020-01-29T08:17:34.115343Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 3040
2020-01-29T08:17:37.355887Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 1ams)egw_38P

#修改/usr/local/mysql 当前目录的用户
chown -R root:root ./
chown -R mysql:mysql data

#复制my-default.cnf文件到etc/my.cnf
cd support-files/
touch my-default.cnf
chmod 777 ./my-default.cnf 
cd ../
cp support-files/my-default.cnf /etc/my.cnf**

#配置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
 
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 5186
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# 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 
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

四、开机自启动

#拷贝mysql.server到init.d并重命名为mysql
cd support-files/
cp mysql.server /etc/init.d/mysql 
chmod +x /etc/init.d/mysql

#注册服务
chkconfig --add mysql
export PATH=/sbin:$PATH
chkconfig
PATH="PATH":/sbin
echo $PATH

#使用命令查看是否注册成功
config --list mysql

#etc/ld.so.conf添加内容配置路径
/usr/local/mysql/lib

#配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

#立即生效
source /etc/profile

#启动mysql服务
service mysql start
mysql -uroot -p[初始化密码]

#修改密码
alter user 'root'@'localhost' identified by '123456';

你可能感兴趣的:(Linux下CentOS 7安装mysql8.0.18以及自启动)