Mysql初级-二进制安装(超详细)

1.二进制安装 官网下载地址:

https://downloads.mysql.com/archives/community/
在这里插入图片描述
在这里插入图片描述

2.软件包下载在/usr/src下
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz 
3.解压在/usr/local下
[root@localhost src]# tar -zxf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost local]# ls 
bin etc games include lib lib64 libexec mysql-5.7.33-linux-glibc2.12-x86_64 sbin share  src
4.创建一个没有家目录,不能登录,系统的mysql普通用户
[root@localhost local]# useradd -r -M -s /sbin/nologin mysql
[root@localhost local]# id mysql
uid=974(mysql) gid=973(mysql) groups=973(mysql)
5.创建软连接方便操作
[root@localhost local]# ln -s mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
6.设置属主属组均是mysql
[root@localhost local]# chown -R mysql.mysql mysql* 
[root@localhost local]# ll
lrwxrwxrwx. 1 mysql mysql 36 May 4 19:47 mysql -> mysql-5.7.33-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 May 4 19:42 mysql-5.7.33-linux-glibc2.12-x86_64
7.设置mysql的环境变量
[root@localhost ~]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql
8.建立数据存放的目录
[root@localhost ~]# mkdir /opt/data 
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
drwxr-xr-x. 2 mysql mysql 6 May 4 20:01 data
9.初始化数据库
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-04T12:07:43.625894Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2021-05-04T12:07:43.820483Z 0 [Warning] InnoDB: New log files created, LSN=457902021-05-04T12:07:43.847352Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2021-05-04T12:07:43.901539Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 54fe2173-acd1-11eb950c-000c298d3571.2021-05-04T12:07:43.903032Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-05-04T12:07:44.806580Z 0 [Warning] CA certificate ca.pem is self signed.2021-05-04T12:07:44.887435Z 1 [Note] A 
temporary password is generated for 
root@localhost: 0%:CmR(uQoXu
#此时我的临时随机密码是:0%:CmR(uQoXu
10.生成配置文件

7.0版本文件是/etc/my.cnf,修改前需备份
8.0版本需自己加

[root@local ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql #安装目录
datadir = /opt/data #数据目录
socket = /tmp/mysql.sock #套接字分俩个目录 /tmp/mysql.sock或/var/lib/mysql/mysql.sock
port = 3306 #端口号
user = mysql #用户
pid-file = /opt/data/mysql.pid #进程文件
skip-name-resolve #跳过域名解析
#skip-grant-tables #跳过密码授权
#server-id=1 #服务id
#log-bin=mysql-bin #开启日志服务
11.mysql.server脚本的配置与启动
#找到mysql.server
[root@localhost support-files]# pwd
/usr/local/mysql/support-files(支持的文件)
[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate (mysql.server)

#确定脚本复制到/init.d下,并且具有执行权限
[root@localhost support-files]# file mysql.server
 mysql.server: POSIX shell script, ASCII text executable(脚本类型)
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/
total 36
-rw-r--r--. 1 root root 18434 Feb 15 23:09 functions
-rwxr-xr-x. 1 root root 10576 May 5 14:32 mysqld
-rw-r--r--. 1 root root 1161 Feb 1 17:04 README
#修改脚本(46,47行)
[root@localhost ~]# vim /etc/init.d/mysqld 
 46 basedir=/usr/local/mysql 
 47 datadir=/opt/data
 #启动方法1:
 [root@localhost ~]# /etc/init.d/mysqld start
 [root@localhost ~]# ss -antl
 LISTEN 0 80 *:3306  *:*
 
  #启动方法2:
  [root@localhost ~]# service mysqld start  #版本6的方式开启
  [root@localhost ~]# chkconfig mysqld on  #开机自启
12.安装 libncurses.so.5使用mysql
1.查看该包是否存在,由什么提供
[root@localhost ~]# dnf provides libncurses.so.5
Last metadata expiration check: 1:14:06 ago on Wed 05 May 2021 01:53:31 PM CST
.ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5
2.安装该包
[root@localhost ~]# dnf -y install ncurses-compat-libs
13.登陆,修改密码
[root@localhost ~]# mysql -uroot -p'0%:CmR(uQoXu'
mysql: [Warning] Using a password on the command line interface can be insecure
.Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates.
 Other names may be trademarks of their respectiveowners.
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 mysql>
#修改密码
mysql> set password = password(‘Huawei0917@’);
14.mysql编译创建的软连接与lib(方便使用)
#头文件include
[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql
#库文件lib
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf
 /usr/local/mysql/lib
 [root@localhost ~]# ldconfig #读取配置文件#可以找到lib文件了
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神慕蔡蔡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值