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 測試:在主節點上建立一個數據庫,看從節點是否也建立了數據庫