首页 > 数据库 >linux (CentOS7.5_x86_64)下安装mysql8.0

linux (CentOS7.5_x86_64)下安装mysql8.0

时间:2023-03-25 11:11:06浏览次数:45  
标签:x86 64 root linux mysqld usr mysql Master local

# 下载mysql

$ wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.13-el7-x86_64.tar.gz

# 解压
$ mysql tar -zxvf mysql-8.0.4-rc-linux-glibc2.12-x86_64.tar.gz -C /usr/local

# 修改文件夹名称
$ mv mysql-8.0.4-rc-linux-glibc2.12-x86_64/ mysql

添加默认配置文件
$ vim/etc/my.cnf

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data


# 创建mysql组
$ groupadd mysql

# 创建mysql用户
$ useradd -g mysql mysql

# 创建mysql数据目录
$ mkdir $MYSQL_HOME/data

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


# 初始化报错
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

# 解决方法
yum install -y libaio

# 初始化报错
2018-07-08T02:53:24.542370Z 0 [System] [MY-010116] /usr/local/mysql/bin/mysqld (mysqld 8.0.4-rc) starting as process 17745 ...
mysqld: Can't create/write to file '/tmp/mysql/data/ibd35qXQ' (Errcode: 13 - Permission denied)
2018-07-08T02:53:24.554816Z 1 [ERROR] [MY-011066] InnoDB: Unable to create temporary file; errno: 13
2018-07-08T02:53:24.554856Z 1 [ERROR] [MY-011066] InnoDB: InnoDB Database creation was aborted with error Generic error. You may need to delete the ibdata1 file before trying to start up again.
2018-07-08T02:53:24.555000Z 0 [ERROR] [MY-010020] Data Dictionary initialization failed.
2018-07-08T02:53:24.555033Z 0 [ERROR] [MY-010119] Aborting
2018-07-08T02:53:24.555919Z 0 [System] [MY-010910] /usr/local/mysql/bin/mysqld: Shutdown complete.

# 解决办法:修改/tmp/mysql的目录权限
$ chown -R mysql:mysql /tmp/mysql


# 初始化成功
> 如果无异常情况日志如下可以看到mysql默认会生成root账号和密码root@localhost: /TI(mjVAs1Ta

[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-01-29T10:19:34.023997Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 4240
2019-01-29T10:19:39.764895Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /TI(mjVAs1Ta
2019-01-29T10:19:43.041419Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed

# 拷贝mysql启动文件到系统初始化目录
$ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld


# 启动mysql服务器
$ service mysqld start

 

 

mysql基本操作

 


# 使用mysql客户端连接mysql
$ /usr/local/mysql/bin/mysql -u root -p password

修改mysql的默认初始化密码
> alter user 'root'@'localhost' identified by 'root';

# 创建用户 CREATE USER '用户名称'@'主机名称' INDENTIFIED BY '用户密码'
> create user 'jack'@'localhost' identified by 'jack';

# 授予权限 grant 权限 on 数据库.表 to '用户名'@'登录主机' [INDENTIFIED BY '用户密码'];
> grant replication slave on *.* to 'jack'@'localhost';

# 刷新
# $ flush privileges;

# 修改root用户可以远程连接
> update mysql.user set host='%' where user='root';

# 查看mysql所用用户
> select user,host from mysql.user;

# docker 修改mysql的最大连接数
apt-get update
apt-get install vim
vim /etc/mysql/mysql.conf.d/mysqld.cnf
max_connections=1000

> alter user 'root'@'%' identified with mysql_native_password by 'root';

 

mysql 主从复制

# 配置主服务添加如下配置
$ vim /etc/my.cnf

# 节点唯一id值
server-id=1

# 开启二进制日志
log-bin=mysql-bin

# 指定日志格式 有mixed|row|statement 推荐mixed
binlog-format=mixed

# 步进值auto_imcrement。一般有n台主MySQL就填n(可选配置)
auto_increment_increment=2

# 起始值。一般填第n台主MySQL。此时为第一台主MySQL(可选配置)
auto_increment_offset=1

# 忽略mysql库(可选配置)
binlog-ignore=mysql

# 忽略information_schema库(可选配置)
binlog-ignore=information_schema

# 要同步的数据库,默认所有库(可选配置)
replicate-do-db=db1


# slave 节点配置

# 节点唯一id值
server-id=2

# 开启二进制日志
log-bin=mysql-bin

# 步进值auto_imcrement。一般有n台主MySQL就填n(可选配置)
auto_increment_increment=2

# 起始值。一般填第n台主MySQL。此时为第一台主MySQL(可选配置)
auto_increment_offset=2

# 要同步的数据库,默认所有库(可选配置)
replicate-do-db=db1


# 查看 master 的状态 , 尤其是当前的日志及位置
> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 1608 | | | |
+------------------+----------+--------------+------------------+-------------------+

# 在slave节点执行如下命令

注意master_log_file 是对应show master status;中file的值,master_log_pos是对应position的值

> change master to
master_host='192.168.79.15',
master_user='root',
master_password='root',
master_log_file='mysql-bin.000009',
master_log_pos=0;

# 启动 slave 状态 ( 开始监听 msater 的变化 )
> start slave;

# 查看 slave 的状态
> show slave status\G

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.79.15
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 863
Relay_Log_File: node-6-relay-bin.000002
Relay_Log_Pos: 500
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 863
Relay_Log_Space: 709
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 6291c709-23af-11e9-99fb-000c29071862
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0

# 当Slave_IO_Running: Yes和Slave_SQL_Running: Yes都为yes是说明主从复制正常


#重置 slave 状态 .
$ reset slave;

#暂停 slave 状态 ;
$ stop slave;

标签:x86,64,root,linux,mysqld,usr,mysql,Master,local
From: https://www.cnblogs.com/message-hrp/p/17254371.html

相关文章

  • about gpasswd/chown/umask/chgrp/chmod command in linux
    adminuserusesudocanbedo:(拥有sudo权限应该做什么?)1:add<username>to<groupname>groupsudogpasswd-a<username><groupname>2:remove<username>from<group......
  • 600 条最强 Linux 命令总结
    1.基本命令uname-m显示机器的处理器架构uname-r显示正在使用的内核版本dmidecode-q显示硬件系统部件-(SMBIOS/DMI)hdparm-i/dev/hda罗列一个磁盘的架构特......
  • Linux系统安装
    一、Linux系统安装1、Linux系统介绍​ Linux一类操作系统的统称​ 适用于安装部署在服务器上​ 服务器:​ 提供服务的机器​ 专业的硬件设备​ pc......
  • 2023 archlinux 启用 Secure Boot (安全启动) 的最简单方法 -- sbctl
    配置背景最近在我的Thinkpad上装了Windows11+Archlinux双系统。想要开启下SecureBoot。其实不开启双系统运行也正常,但由于Windows上的WSA和部分游戏的安全......
  • Linux——命令(一)
    在虚拟机中,打开Linux系统,登录root用户,便可看到一串字符串[root@localhost~]#[当前用户名@简写主机名~]#root:显示的是当前的登录用户 @:分隔符号,没有特殊含义。l......
  • Linux修改显示屏分辨率
    一、修改U-boot屏幕参数修改对应屏幕的参数修改->ARMarchitecture->EnablegraphicalubootconsoleonHDMI,LCDorVGA底下括号的参数:例如(1024x600):x:1024,y......
  • Linux中/etc下面passwd shadow group gshadow文件介绍,以及etc目录下login.defs和etc
    一、用户信息文件:/etc/passwd[root@localhost~]#cat/etc/passwd#查看一下文件内容root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:......
  • Linux中mujoco_py添加环境变量以及在pycharm中编辑配配置环境变量的问题
    在经过一系列的操作装好mujoco之后,需要配好环境变量才能最终成功的运行!经过一段时间的折腾,博主总结一下三处在Linux中需要配置环境的地方:1、.bashrc文件博主习惯使用gedi......
  • Linux 软连接和硬链接的区别
    阅读目录一、Linux链接概念1、【硬连接】2、【软连接】二、通过实验加深理解三、总结归纳一、Linux链接概念Linux链接分两种:一种被称为硬链接(HardLink)一种被称为符号链接(S......
  • Linux rm 删除指定文件外的其他文件 方法汇总
    一、Linux下删除文件和文件夹常用命令如下:rmfile#删除文件rm-rfdir#删除文件夹#需要注意的是,rmdir只能够删除空文件夹。 二、删除制定文件(夹)之外的所有文件......