清清楚楚15步 linux服务器安装mysql8.0 安排的明明白白

请先主要看图片 我放的命令没有图片中的全,耐心一点!!就按着我的路径来,先不要创新!基本就会特别顺利!

0.下载tar包:

在 win10 下先下载包
https://dev.mysql.com/downloads/mysql/
在这里插入图片描述
我下载的是mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz

1.现在在 /usr/local下 创建mysql文件夹

mkdir mysql

2.切换到mysql文件夹下 cd mysql

3.通过xft或者RZ命令将包传进去。

在这里插入图片描述

4.包有了之后,解压出来

 tar -xvJf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz

在这里插入图片描述

5. 改一下文件名字方便后安装失败糊涂了需要卸载,太长了也不方便使用

mv mysql-8.0.17-linux-glibc2.12-x86_64 mysql8.0

6.进入解压后的数据库安装包,创建data文件夹

在这里插入图片描述

7. 然后创建mysql的用户和用户组以及修改mysql用户的密码

groupadd mysql
Useradd -g mysql mysql
Passwd mysql

创建用户及用户组

  • 用户组
groupadd mysql
  • 用户 (用户名/密码)
useradd -g mysql mysql

提示报少于8个字符没关系 再输入一次确认回车就行了!
在这里插入图片描述

8.授权用户

chown -R mysql:mysql /usr/local/mysql/mysql8.0

在这里插入图片描述

9.切换到bin目录下面,进行初始化,会初始化密码在@loaclhost里面

完整代码:

 ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0/ --datadir=/usr/local/mysql/mysql8.0/data/ --initialize ;

在这里插入图片描述

10.然后编辑my.cnf文件,注释mysqld_safe 下面是我的参数,仅做参考

直接 vim /etc/my.cnf编辑或者新建配置文件

如果说自己文件夹不存在my.cnf的话 ,自己建一个就行。如果不存在,就会默认新建!!

要是搞不清楚除了显示配置之外还需要的配置,可以将原来的my.cnf备份一份!(用之前传入压缩包的工具直接复制出来备份就行)

然后全部复制我的配置内容修应该需要的部分。

# Example MySQL config file for small systems.  
#  
# This is for a system with little memory (<= 64M) where MySQL is only used  
# from time to time and it's important that the mysqld daemon  
# doesn't use much resources.  
#  
# MySQL programs look for option files in a set of  
# locations which depend on the deployment platform.  
# You can copy this option file to one of those  
# locations. For information about these locations, see:  
# http://dev.mysql.com/doc/mysql/en/option-files.html  
#  
# In this file, you can use all long options that a program supports.  
# If you want to know which options a program supports, run the program  
# with the "--help" option.  

# The following options will be passed to all MySQL clients  
[client]  
default-character-set=utf8  
#password   = your_password  
port        = 3306 
socket      = /tmp/mysql.sock  

# Here follows entries for some specific programs  

# The MySQL server   
[mysqld]  

#配置mysql的文件夹 和 mysql data目录
basedir=/usr/local/mysql/mysql8.0
datadir=/usr/local/mysql/mysql8.0/data
default-storage-engine=INNODB  
character-set-server=utf8  
collation-server=utf8_general_ci  
port        = 3306 
socket      = /tmp/mysql.sock  
skip-external-locking  
key_buffer_size = 16K  
max_allowed_packet = 1M  
table_open_cache = 4 
sort_buffer_size = 64K  
read_buffer_size = 256K  
read_rnd_buffer_size = 256K  
net_buffer_length = 2K  
thread_stack = 128K  

# Don't listen on a TCP/IP port at all. This can be a security enhancement,  
# if all processes that need to connect to mysqld run on the same host.  
# All interaction with mysqld must be made via Unix sockets or named pipes.  
# Note that using this option without enabling named pipes on Windows  
# (using the "enable-named-pipe" option) will render mysqld useless!  
#   
#skip-networking  
server-id   = 1 

# Uncomment the following if you want to log updates  
#log-bin=mysql-bin  

# binary logging format - mixed recommended  
#binlog_format=mixed  

# Causes updates to non-transactional engines using statement format to be  
# written directly to binary log. Before using this option make sure that  
# there are no dependencies between transactional and non-transactional  
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM  
# t_innodb; otherwise, slaves may diverge from the master.  
#binlog_direct_non_transactional_updates=TRUE  

# Uncomment the following if you are using InnoDB tables  
#innodb_data_home_dir = /usr/local/mysql/data  
#innodb_data_file_path = ibdata1:10M:autoextend  
#innodb_log_group_home_dir = /usr/local/mysql/data  
# You can set .._buffer_pool_size up to 50 - 80 %  
# of RAM but beware of setting memory usage too high  
#innodb_buffer_pool_size = 16M  
#innodb_additional_mem_pool_size = 2M  
# Set .._log_file_size to 25 % of buffer pool size  
#innodb_log_file_size = 5M  
#innodb_log_buffer_size = 8M  
#innodb_flush_log_at_trx_commit = 1 
#innodb_lock_wait_timeout = 50 

[mysqldump]  
quick  
max_allowed_packet = 16M  

[mysql]  
no-auto-rehash  
# Remove the next comment character if you are not familiar with SQL  
#safe-updates  

[myisamchk]  
key_buffer_size = 8M  
sort_buffer_size = 8M  

[mysqlhotcopy]  
interactive-timeout 

按esc 英文输入法下打出
然后输入x 即可保存退出

11.配置文件改好了之后,然后修改数据库服务的配置文件

vim /usr/local/mysql/mysql8.0/support-files/mysql.server

在这里插入图片描述
在这里插入图片描述

12将数据库的服务添加到系统并授权

 cp -a ./support-files/mysql.server /etc/init.d/mysql
 chmod 755 /etc/init.d/mysql
 chkconfig --add mysql
 chkconfig --list 可以查看

在这里插入图片描述
则说明成功了

13.然后现在就可以启动mysql的服务了

Service mysql start
如果报蓝色方框的错误,又是复制的我的配置文件内容,那么很大很大概率是因为路径配错了 (basedir和datadir)
在这里插入图片描述

14.将mysql命令添加到服务

   ln -s /usr/local/mysql/mysql8.0/bin/mysql   /var/bin 

(请注意自己前面填写的路径)
在这里插入图片描述

15.登陆mysql修改密码,并使密码立即生效

登录

mysql -uroot -p

输入之前默认生成的密码

若出现mysql未找到命令:那是因为你没把mysql加入到系统环境中

vim /etc/profile 文件,加入如下代码,(也就是配置环境变量)

然后执行 source /etc/profile 命令

在这里插入图片描述

再次登录就没问题了

修改root密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';

其中12345678是新的密码自己设置,执行flush privileges;使密码立即生效;

16.选择数据库,修改远程连接并生效

use mysql;

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

flush privileges;

在这里插入图片描述
安装就完毕了,下次登陆的时候就用刚才设置的那个密码去登陆。

然后任意环境下测试MySQL登陆,都是可以正常登陆的,至此,mysql安装以及基本配置就结束了!!

此时应该用quit退出数据库 再进行防火墙的操作

请注意此时的linux是可以远程连接的 如果说 连接不上 很大程度是因为防火墙的原因
执行 systemctl stop firewalld.service 即可关闭防火墙!
(首先要确定自己的服务器安装了system)
如果执行systemctl stop firewalld.service报错
判断自己是否安装了systenctl执行systemctl --version
然后应该就可以连接了

安装数据库启动不了的主要问题就是 !配置文件的问题,多多注意一一下
在这里插入图片描述

或者说将3306端口加入防火墙( 加入防火墙了以后需要linux重启一下reboot

firewall-cmd --zone=public --add-port=3306/tcp --permanent

这是对命令的解释
## zone --> 作用域
## add-port=80/tcp --> 添加端口,格式为:端口/通讯协议
## permanent --> 永久生效,没有此参数重启后失效

需要在防火墙开启时执行

1. 查看防火墙状态

三条命令都可以用
firewall-cmd --state           
systemctl status firewalld.service 
service firewalld status

2. 关闭防火墙

三条命令都可以用
systemctl stop firewalld.service
systemctl disable firewalld.service
service firewalld stop

3. 开启防火墙

2条命令都可以用
systemctl start firewalld.service
service firewalld start

4. 重启防火墙

两条命令都可以用
firewall-cmd --reload
service firewalld restart

查询端口号3306 是否开启

##查询端口号3306 是否开启
firewall-cmd --query-port=3306/tcp

附件:了解常见的mysql配置文件含义

# MySQL 配置文件,
# 数据库目录 /data/mysql
[client]
port=3306
# mysql socket 文件存放地址
socket=/tmp/mysql.sock
# 默认字符集
default-character-set=utf8
[mysqld]
server-id=1
# 端口
port=3306
# 运行用户
user=mysql
# 最大连接
max_connections=200
socket=/tmp/mysql.sock
# mysql 安装目录(解压后文件的目录)
basedir=/usr/local/mysql
# 数据目录(这里放在我们新建的 /data/mysql 下)
datadir=/data/mysql
pid-file=/data/mysql/mysql.pid
init-connect='SET NAMES utf8'
character-set-server=utf8
# 数据库引擎
default-storage-engine=INNODB
log_error=/data/mysql/mysql-error.log
slow_query_log_file=/data/mysql/mysql-slow.log
# 跳过验证密码
#skip-grant-tables
[mysqldump]
quick
max_allowed_packet=16M
EOF
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值