首页 > 数据库 >linux 系统安装 mysql 或者 主从

linux 系统安装 mysql 或者 主从

时间:2022-11-08 11:13:42浏览次数:61  
标签:log root app linux user mysql data 主从

mysql-5.7.18-linux-glibc2.5安装

1.检查所使用的linux下是否有安装过mysql
rpm -qa|grep -i mysql
2.删除安装过的mysql
rpm -e mysql-5.7.18-linux-glibc2.5-x86_64 --nodeps //载时使用了--nodeps选项,忽略了依赖关系
3.创建mysql的用户组/用户, data目录及其用户目录
userdel mysql

groupdel mysql

--

mkdir -p /app/data/mysql/app

mkdir -p /app/data/mysql/data

groupadd mysql

useradd -g mysql -M mysql

chown -R mysql:mysql /app/data/mysql/app

4.解压安装包并将解压包里的内容拷贝到mysql的安装目录/data/mysql/app
tar -xzvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.18-linux-glibc2.5-x86_64/* /app/data/mysql/app

rm -rf mysql-5.7.18-linux-glibc2.5-x86_64
5.初始化mysql数据库
/app/data/mysql/app/bin/mysqld --user=mysql --basedir=/app/data/mysql/app --datadir=/app/data/mysql/data --initialize

初始化出现错误的时候

--/data/mysql/app/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
使用命令---yum install -y libaio
密码
k4/ywwfSu5uw

6.复制mysql服务启动脚本及加入PATH路径

sed -i '52a\export PATH=/app/data/mysql/app/bin:/app/data/mysql/app/lib:$PATH' /etc/profile

source /etc/profile

  1. 复制mysql服务启动配置文件
    
  2. cp /app/data/mysql/app/support-files/mysql.server /etc/init.d/mysqld

  3. chmod a+x /etc/init.d/mysqld

添加:vi /etc/my.cnf
------------------------------------------------------------------------------------------------#
[mysqld]
datadir=/app/data/mysql/data
basedir =/app/data/mysql/app
socket=/app/data/mysql/app/mysql.sock

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

join_buffer_size = 8M
sort_buffer_size = 8M
read_rnd_buffer_size = 8M

建议是运行内存的一半

innodb_buffer_pool_size = 16G
max_connections=2000
max_allowed_packet = 20971520
lower_case_table_names=1
tmp_table_size=1073741824
max_heap_table_size=1073741824
query_cache_size=4M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
general_log=on(默认关闭,off)
gtid_mode=ON
enforce_gtid_consistency = ON

Settings user and group are ignored when systemd is used.

If you need to run mysqld under a different user or group,

customize your systemd unit file for mariadb according to the

instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mysql.log
pid-file=/var/run/mysql.pid

[client]
socket=/app/data/mysql/app/mysql.sock

include all files from the config directory

------------------------------------------------------------------------------------------------#

8.启动mysql服务并加入开机自启动
service mysqld start

chkconfig --level 35 mysqld on
9.检查mysql服务是否启动
netstat -tulnp |grep 3306

10.修改root默认密码
mysql -u root -p

alter user 'root'@'localhost' identified by '789oiU&*';
flush privileges;

====开启root账号远程
use mysql;
update user set host ='%' where user = 'root';

  1. 创建数据库及用户并授权 (db_name为数据库名称)
    CREATE DATABASE master DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;(新建test_ejob)

==创建用户
CREATE USER 'slave'@'host' IDENTIFIED BY '123qwe';
---CREATE USER 'videotest'@'host' IDENTIFIED BY '789oiU&';
select host,user from mysql.user;(查询系统所有用户)
update mysql.user set host='%' where user='slave';
---修改用户的密码
update mysql.user set authentication_string=password('123qwe') where user='wangjiazhen' and Host = '%';
flush privileges;(注意:不管操作了什么 都要刷新哦)
===授权:(让创建的用户有操作数据库的权限)
GRANT all privileges ON videocustomer.
TO 'videotest'@'%' ;

验证:mysql -u video -p

GRANT ALL PRIVILEGES ON . TO root@'%' IDENTIFIED BY  '789oiU&*';
 grant replication slave on *.* to 'cmcc'@'192.168.168.103' identified by 'Frontier@1234';
 grant all privileges on tsznyy.* to wangjiazhen@'%' identified by '123qwe';(%:任何地方都能登录,不限制IP;localhost:只能本服务器登录;10.10.40.142:)
 (all privileges:所有权限;select:查询权限)grant all privileges on *.* to root@'%'   WITH GRANT OPTION
 (grant select,update on test_ejob.* to test_tmzl@'%' identified by '789oiU&*';)


 use mysql
 select host,user from mysql.user;(查询系统所有用户)
 Delete FROM user Where User='videotest' and Host='%';(删除某个mysql用户:先进入use mysql,然后再删除,根据User和Host为唯一主键)

 grant all privileges on carlife.* to clms@'%' identified by '789oiU&*';

故障处理
(输入exit退出先)

  1. 忘记默认密码处理方式:
    vi /etc/my.cnf

    添加: skip-grant-tables

    重启mysql: service mysqld restart

    进入mysql:mysql -u root -p 回车,跳过密码,不用输入

    mysql>update mysql.user set authentication_string=password('123qwe') where user='wangjiazhen' and Host = '%';

    exit

    vi /etc/my.cnf

    删除 skip-grant-tables

    重启mysql

    service mysqld restart

2.mysql 8 报错 caching-sha2-password 时的处理方法

创建用户

CREATE USER 'wangjiazhen'@'%' IDENTIFIED BY 'wangjiazhen';

授权用户权限

grant all privileges on wangjiazhen.* to 'wangjiazhen'@'%';

客户端连接报错时的处理方法(在安装mysql8的时候如果选择了密码加密,之后用客户端连接比如navicate,会提示客户端连接caching-sha2-password,是由于客户端不支持这种插件,可以通过如下方式进行修改:)

ALTER USER 'nfl_risk'@'%' IDENTIFIED BY 'nfl_risk' PASSWORD EXPIRE NEVER;

ALTER USER 'nfl_risk'@'%' IDENTIFIED WITH mysql_native_password BY '{nfl_risk}';

grant all on . to 'root'@'%' identified by '789oiU&*' with grant option;

==============mysql主从复制 异步复制
主服务器
1.创建日志二进制日志目录
mkdir /app/data/mysql/mysqldata
chown -R mysql:mysql /app/data/mysql/mysqldata
2.执行 vi /etc/my.cnf
新增
log-bin=/app/data/mysql/mysqldata/mysql-bin #开启二进制日志
server-id=17514 #设置server-id,服务器唯一编号
===============以下可以不用
#临时缓存最小256K
binlog_cache_size=256K
#临时缓存不能超过200M
max_binlog_cache_size=200M
#设置日志不能超过200M超过就会切分
max_binlog_size=200M
#不记录每条sql语句的上下文信息,仅需记录哪条数据被修改了,修改成什么样了。而且不会出现某些特定情况下
#的存储过程、或function、或trigger的调用和触发无法被正确复制的问题。缺点是会产生大量的日志,尤其是
#alter table的时候会让日志暴涨。
binlog-format=ROW
sync_binlog=1000
#如果从库可能成功主库 就需要加 注意:从节点配置文件加入log-slave-updates=1,同步异常慢
log-slave-updates=1
#保留日志7天
expire_logs_days=7
===============

	保存之后重启mysql服务:service mysqld restart
	登录mysql:mysql -u root -p
3.重启mysql,创建用于同步的用户账号
	创建用户‘cmcc’,密码‘Frontier@1234’,并给从服务器授权
	grant replication slave on *.* to 'cmcc'@'192.168.254.133' identified by 'Frontier@1234';
	flush privileges;

从数据库配置:
1.创建日志二进制日志目录
mkdir /app/data/mysql/mysqldata
chown -R mysql:mysql /app/data/mysql/mysqldata
2.执行 vi /etc/my.cnf
新增
log-bin=/app/data/mysql/mysqldata/mysql-bin #开启二进制日志
server-id=17515 #设置server-id,服务器唯一编号
保存之后重启mysql服务:service mysqld restart
登录mysql:mysql -u root -p
3.重启mysql,创建用于同步的用户账号 master_port=33066 如果端口位3306的时候可以默认不写
#master_log_file和master_log_pos是根据 show master status中的数据
change master to master_host='192.168.254.132',master_user='cmcc',master_password='Frontier@1234',master_log_file='mysql-bin.000001',master_log_pos=154;

	 开启同步功能;start slave;
	查看从库状态:show slave status\G;

测试创建数据库:
1.在主库创建drm和drm_log数据库
[root@host-192-168-85-5 mysql]# mysql -u root -p 输入密码
执行创建数据库操作:create database drm;
执行创建数据库操作:create database drm_log;
查看数据语句:show databases;

标签:log,root,app,linux,user,mysql,data,主从
From: https://www.cnblogs.com/leasing/p/16869000.html

相关文章