1 先从安装mysql (liunx中安装的方法为)html
系统为:centos5.8 + mysql8.0.13java
第一步:查看mysql是否安装。 rpm -qa|grep mysql 第二步:若是mysql的版本不是想要的版本。须要把mysql卸载。 yum remove mysql mysql-server mysql-libs mysql-common rm -rf /var/lib/mysql rm /etc/my.cnf 第三步:安装mysql。须要使用yum命令安装。在安装mysql以前须要安装mysql的下载源。须要从oracle的官方网站下载。 1)下载mysql的源包。 咱们是centos6.4对应的rpm包为:mysql-community-release-el6-5.noarch.rpm 2)安装mysql下载源: (下载地址:https://dev.mysql.com/downloads/repo/yum/) yum localinstall mysql-community-release-el6-5.noarch.rpm 3)在线安装mysql: yum install mysql-community-server 第四步:启动mysql service mysqld start 第五步:须要给root用户设置密码。 /usr/bin/mysqladmin -u root password 'new-password' // 为root帐号设置密码 第六步:远程链接受权。 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 注意:'myuser'、'mypassword' 须要替换成实际的用户名和密码。
若是再安装中报以下错误mysql
mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
进行以下操做(安装的是mysql_8.0.13数据库)sql
参考以下几篇博客:1:https://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno数据库
2: https://www.aliyun.com/jiaocheng/1392591.htmlvim
3:https://blog.csdn.net/cartoon_/article/details/80344637centos
service mysqld stop vim /etc/my.cnf (在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程) [root@MiWiFi-R3-srv shitool]# service mysqld restart 2018-12-20T16:23:29.666776Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [3]- Done mysqld_safe --skip-grant-tables [root@MiWiFi-R3-srv shitool]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. #MySQL5.7和以前的用户修改密码方式: mysql -uroot -e "Set password=password(‘123’);" mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456') where user='root';" update mysql.user set authentication_string=password("123") where user='root'; #以上三种方法在MySQL8.0之后版本中将不能使用,若是使用了将会致使在正确修改密码是报以下错误: mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123'; ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost' 如赶上以上问题请使用update语句先清空authentication_string字段,而后再修改密码便可 完整的执行流程 update user set authentication_string='' where user='root'; mysql> flush privileges; 必需要刷新权限 Query OK, 0 rows affected (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码'; Query OK, 0 rows affected (0.06 sec) #mysql8.0以后都是使用这个修改用户密码的 mysql> exit; Bye 而后删除: vim /etc/my.cnf (在[mysqld]后面任意一行删除“skip-grant-tables”用来跳过密码验证的过程) vim /etc/my.cnf [root@MiWiFi-R3-srv ~]# service mysqld restart 修改全部ip均可以访问: select host,user from user; update user set host='%' where user ='root'; 退出 使用用户名密码登陆 [root@MiWiFi-R3-srv ~]# mysql -u root -p 查看mysql的版本 mysqladmin --version
2 配置主从复制服务器
主(master): 192.168.3.243 OS:CentOS 6.8 从(slave2): 192.168.11.1166 OS:CentOS 6.8 mysql的版本:社区版8.0.13
2.1 先配置主节点oracle
1 编辑 vim /etc/my.cnf [mysqld] server-id=243 #设置主服务器的ID,能够任意配置可是多个主从之间不能重复 innodb_flush_log_at_trx_commit=2 # sync_binlog=1 #开启binlog日志同步功能 log-bin=mysql-bin-121 #binlog日志文件名(能够任意命名) 2 重启服务,使用用户名密码登录 service mysqld restart mysql -u root -p 3 建立用户而且赋值权限 create user '用户名'@'访问主机' identified by '密码'; #建立帐户 grant 权限列表 on 数据库 to '用户名'@'访问主机';# (修改权限时在后面加with grant option) 赋予权限: 如: create user 'shi'@'192.168.3.166' identified by 'shiye'; grant replication slave on *.* to 'shi'@'192.168.3.166' with grant option; flush privileges; #刷新权限 4 查看状态 show master status; ##查看主库的状态 file,position这两个值颇有用。要放到slave配置中
2.2 配置从从节点ide
1 编辑文件 vim /etc/my.cnf server-id=122 innodb_flush_log_at_trx_commit=2 sync_binlog=1 log-bin=mysql-bin-122 2 重启服务,登录mysql service mysqld restart mysql -uroot -p mysql>stop slave; 3 配置连接属性 CHANGE MASTER TO MASTER_HOST='192.168.3.243', MASTER_USER='shi', #若是不行就用root权限 MASTER_PASSWORD='shiye', MASTER_LOG_FILE='mysql-bin-121.000002', MASTER_LOG_POS=325; 4 show slave status\G; #Slave_IO_Running,Slave_SQL_Running 都为Yes的时候表示配置成功
2.3 测试:在主节点上建立一个数据库,看从节点是否也建立了数据库