Linux(CentOS)中安装MySQL

下载mysql并放到Linux系统

官网下载linux系统下的mysql,地址:mysql官网
我的Linux虚拟机是CentOS的,所以选择的是Linux通用版本的MySQL

在这里插入图片描述
通过xftp工具,将mysql压缩包放到linux系统的 /opt目录下:
在这里插入图片描述
解压包:

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

在这里插入图片描述
将解压好的文件复制并放在 /usr/local路径下,重命名为mysql:

cp -r mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local/mysql

在这里插入图片描述

配置环境变量

执行命令:

vi /etc/profile

添加系统的环境变量:

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

执行下列命令使配置文件生效:

source /etc/profile

创建mysql用户组和mysql用户

groupadd mysql
useradd -r -g mysql mysql

授权
注意,一定要进入mysql目录下进行授权操作

chown -R mysql:mysql ./

在这里插入图片描述

修改mysql用户密码

passwd mysql 

在这里插入图片描述

初始化数据库

他会生成一个随机密码,这里需要记一下,一会登录时使用

 bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

在这里插入图片描述

修改data文件的用户组:

chown [选项]… [所有者][:[组]] 文件…

chown -R root:root ./
chown -R mysql:mysql data

在这里插入图片描述

创建my-default.cnf 文件

进入到mysql中的support-files文件,并创建my-default.cnf文件

touch my-default.cnf

为该文件授权:

chmod 777 ./my-default.cnf 

在这里插入图片描述
将该文件复制到指定目录
cp support-files/my-default.cnf /etc/my.cnf
在这里插入图片描述

配置my.cnf文件

vim /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

注册服务

注意当前路径应该在mysql8.0,即support-files的根目录)

添加Mysql到系统服务

cp -a ./support-files/mysql.server /etc/init.d/mysql   # 若mysqld,以下mysql相应的修改mysqld,如下图所示
chmod +x /etc/init.d/mysql
chkconfig --add mysql

检查服务是否生效

chkconfig --list mysql

在这里插入图片描述

etc/ld.so.conf配置路径

vim /etc/ld.so.conf

添加如下内容:

/usr/local/mysql/lib

在这里插入图片描述

登录

启动mysql服务

service mysql start

在这里插入图片描述
查看启动状态:

service mysql status;

在这里插入图片描述

登录mysql

mysql -uroot -p

在这里输入刚才生成的初始密码
在这里插入图片描述

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值