linux安装mysql8.0.18

参考 https://blog.csdn.net/atongmu2017/article/details/90610444

好我们正式开始

首先下载linux的mysql
云盘链接:链接:https://pan.baidu.com/s/1Vyl_UQfYBaWa0vkki2_C0Q
提取码:0kip

上传mysql到linux服务器上

rz  // 选择文件即可

若没有则执行这个命令,安装这个包

yum install -y lrzsz

在这里插入图片描述
在这个界面选择文件即可。

输入 ls -a 查看传进来的文件

ls -a    

在这里插入图片描述

解压文件

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

在这里插入图片描述

给解压后的文件移动到/usr/local目录下,并重命名为mysql

mv mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz  /usr/local/mysql

cd /usr/local/mysql    //进入到mysql文件夹中

mkdir  data    // 在mysql文件中创建 data文件夹

在这里插入图片描述

进入 /usr/local 目录 ,创建用户和用户组权限

groupadd  mysql //添加用户组  名为mysql

useradd  -r -g mysql  mysql  创建mysql用户,并列出mysql用户组

进入 /usr/local/mysql 目录下 ,对刚才创建的用户和用户组进行授权

chown -R mysql:mysql ./   //授权

在这里插入图片描述

初始化数据库,系统会生成随机密码,一定要记录下来!

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

在这里插入图片描述

修改/usr/localmysql当前用户的目录

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

在这里插入图片描述

在/usr/local/mysql/support-files下创建my-default.cnf,并配置权限,然后将其复制到/etc下并命名为 my.cnf

cd  /support-files   //进入该目录

touch my-default.cnf   // 创建文件

chmod 777 ./my-default.cnf  //文件授权

cp my-default.cnf  /etc/my.cnf

在这里插入图片描述

配置/etc/my.cnf

vim /etc.my.cnf     //  进入后输入  i  是从命令模式进入到输入模式 ,此时才可进行修改

my.cnf可写入的配置 编写完成后,按esc退出输入模式,然后按":"切换到底线命令模式,然后在输入 "wq!"保存即可.

[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

设置开机自动启动

cd /support-files     //进入到/usr/local/mysql/support-files中

cp mysql.server  /etc/init.d/mysql   //复制mysql.server到/etc/init.d中并命名为mysql

chmod +x /etc/init.d/mysql   给/etc/init.d/mysql  添加执行权限

注册服务

chkconfig --add mysql  // 注册服务

chkconfig  --list  mysql  //查看是否成功

在这里插入图片描述

对/etc/ld.so.conf 进行配置

vim /etc/ld.so.conf    

添加如下内容

/usr/local/mysql/lib

在这里插入图片描述

配置环境变量

vim  /etc/profile

添加如下内容:
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

在这里插入图片描述

终于到了登录这个步骤了

service mysql  start  //启动mysql

mysql -uroot -p   //  登录myqsl,然后输入刚才让你们保存的密码

alter user 'root'@'localhost' identified by 'root';  // 修改mysql的密码

在这里插入图片描述

最后一步 让mysql可以被远程连接

select user,host from user;

update user set host='%' where user='root';

flush privileges;

若远程连接mysql的软件是SQLyog,此时连接会出现错误码2058的错误,只需要输入一句话即可

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';  //password 是你的密码

然后我们就真的弄完了!!! 出错儿了的话就删除重来吧 ,多试几次总可以的!
附上linux卸载mysql的链接 https://blog.csdn.net/qq_41829904/article/details/92966943

发布了2 篇原创文章 · 获赞 1 · 访问量 106

猜你喜欢

转载自blog.csdn.net/weixin_45114726/article/details/104449841