一、解壓縮,好比到d:\,爲了方便,改一下路徑,好比mysql
二、開始/運行,輸入cmd,回車進入命令行
d:
cd mysql\bin
安裝mysql服務
mysqld.exe --install (默認服務名稱是mysql或者mysqld.exe --install "mysql5"修改服務名稱)
刪除mysql服務
mysqld.exe --remove(或者mysqld.exe --remove "mysql5")
三、ini參數配置文件d:\mysql\
複製mysql-small.ini爲my.ini
四、啓動中止服務
a)在命令行啓動/中止
net start mysql
net stop mysql
b)或者去控制面板找服務啓動
c)或者開始/運行輸入services.msc,肯定後,找到mysql啓動css
原來只在進入 C:\Window 找到CMD.EXE 右鍵選擇 以管理員身份 進行,再進入相應目錄執行命令,一切就OVER 了。html
爲何會出現這個問題呢?通過一番思考找到緣由了,是由於當前用戶的操做權限過低了,出了問題mysql
出錯問題截屏以下:linux
解決問題方法以下:nginx
在dos下運行net start mysql 不能啓動mysql!提示發生系統錯誤 5;拒絕訪問!切換到管理員模式就能夠啓動了。因此咱們要以管理員身份來運行cmd程序來啓動mysql。sql
那麼如何用管理員身份來運行cmd程序呢?shell
1.在開始菜單的搜索框張收入cmd,而後右鍵單擊,並選擇以管理員身份運行!數據庫
若是天天都要啓動mysql服務,這樣不很麻煩?因此:windows
2.右鍵單擊cmd選擇「附到【開始】菜單(U)」;這是就能夠到開始菜單上找到cmd了,centos
3.右擊選擇屬性,選擇快捷方式,再選擇高級,在選擇以管理員身份運行,再單擊肯定便可!
之後只要打開開始菜單單擊上面的快捷方式就能夠以管理員的身份運行cmd了!
這樣再輸入net start mysql就不會出錯了!
access denied for user 'root'@'%' to database xxxx的提示
錯誤的緣由是root用戶在遠程鏈接的MYSQL上面,沒有這個新數據庫的受權。在本地使用mysql應該不存在這個問題。
解決方法,執行受權:
grant all PRIVILEGES on xxxx.* to root@'%' identified by 'password' with grant option;
xxxx爲建立的數據庫,password爲root的密碼。請按實際要求進行更改。
安裝完成卻發現Myserver安裝缺失,在網上找緣由,原來是由於CentOS 7上把MySQL從默認軟件列表中移除了,用MariaDB來代替,因此這致使咱們必需要去官網上進行下載,找到連接,用wget打開:
a: #wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
b:rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost mysql]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 準備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-release-el7-5 ################################# [100%] [root@localhost mysql]# service mysqld start Redirecting to /bin/systemctl start mysqld.service Failed to start mysqld.service: Unit not found. [root@localhost mysql]
c.兩次進行yum -y install mysql mysql-server mysql-devel,安裝成功。再次使用該命令,而後獲得如下信息
[root@localhost mysql]# yum -y install mysql mysql-server mysql-devel 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * epel: mirror01.idc.hinet.net * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 37 kB 00:00:00 (2/3): mysql-tools-community/x86_64/primary_db | 54 kB 00:00:00 (3/3): mysql56-community/x86_64/primary_db | 218 kB 00:00:01 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 mariadb.x86_64.1.5.5.60-1.el7_5 將被 取代 ---> 軟件包 mariadb-server.x86_64.1.5.5.60-1.el7_5 將被 取代 ---> 軟件包 mysql-community-client.x86_64.0.5.6.43-2.el7 將被 捨棄 --> 正在處理依賴關係 mysql-community-libs(x86-64) >= 5.6.10,它被軟件包 mysql-community-client-5.6.43-2.el7.x86_64 須要 ---> 軟件包 mysql-community-devel.x86_64.0.5.6.43-2.el7 將被 安裝 ---> 軟件包 mysql-community-server.x86_64.0.5.6.43-2.el7 將被 捨棄 --> 正在處理依賴關係 mysql-community-common(x86-64) = 5.6.43-2.el7,它被軟件包 mysql-community-server-5.6.43-2.el7.x86_64 須要 --> 正在檢查事務 ---> 軟件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 將被 取代 ---> 軟件包 mysql-community-common.x86_64.0.5.6.43-2.el7 將被 安裝 ---> 軟件包 mysql-community-libs.x86_64.0.5.6.43-2.el7 將被 捨棄 --> 解決依賴關係完成 ... ... ... 已安裝: mysql-community-client.x86_64 0:5.6.43-2.el7 mysql-community-devel.x86_64 0:5.6.43-2.el7 mysql-community-libs.x86_64 0:5.6.43-2.el7 mysql-community-server.x86_64 0:5.6.43-2.el7 做爲依賴被安裝: mysql-community-common.x86_64 0:5.6.43-2.el7 替代: mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-libs.x86_64 1:5.5.60-1.el7_5 mariadb-server.x86_64 1:5.5.60-1.el7_5 完畢! [root@localhost mysql]#
[root@localhost mysql]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@localhost mysql]#
[root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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. mysql>
service mysqld status
systemctl status mysqld.service(也是系統自動輸出的,我這邊全稱是:Redirecting to /bin/systemctl status mysqld.service)
而後會輸出一大段關於MySQL狀態的信息:
[root@localhost bin]# service mysqld status Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Community Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2019-03-28 13:51:31 CST; 2min 1s ago Process: 52885 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS) Process: 52822 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 52884 (mysqld_safe) Tasks: 23 Memory: 237.9M CGroup: /system.slice/mysqld.service ├─52884 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─53050 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --so... 3月 28 13:51:29 localhost.localdomain mysql-systemd-start[52822]: 2019-03-28 13:51:29 52860 [Note] InnoDB: Starting shutdown... 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: 2019-03-28 13:51:30 52860 [Note] InnoDB: Shutdown completed; log sequence number 1625987 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: To do so, start the server, then issue the following commands: 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: /usr/bin/mysqladmin -u root password 'new-password' 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' 3月 28 13:51:30 localhost.localdomain mysql-systemd-start[52822]: Alternatively you can run: 3月 28 13:51:31 localhost.localdomain mysqld_safe[52884]: 190328 13:51:31 mysqld_safe Logging to '/var/log/mysqld.log'. 3月 28 13:51:31 localhost.localdomain mysqld_safe[52884]: 190328 13:51:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 3月 28 13:51:31 localhost.localdomain systemd[1]: Started MySQL Community Server. [root@localhost bin]#
Mysql5.7默認安裝以後root是有密碼的。
爲了增強安全性,MySQL5.7爲root用戶隨機生成了一個密碼,在error log中,關於error log的位置,若是安裝的是RPM包,則默認是/var/log/mysqld.log。
只有啓動過一次mysql才能夠查看臨時密碼
grep 'temporary password' /var/log/mysqld.log(若是以前安裝過MySQL則這裏可能會有多個密碼,用最後一個,注意這個密碼輸入時是能夠粘貼的)
YdsGaxOq>2n!
使用默認的密碼登錄
mysql -uroot -p(這是一個MySQL的以密碼登陸root用戶的命令)
用該密碼登陸到服務端後,必須立刻修改密碼再執行一些數據庫操做,否則會報以下錯誤:
mysql> select @@log_error; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>
修改密碼(注意,登陸後的操做後面都最好要有;結尾)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
若是密碼設置太簡單出現如下的提示
必須修改兩個全局參數:
首先,修改validate_password_policy參數的值
mysql> set global validate_password_policy=0;
再修改密碼的長度
set global validate_password_length=1;
再次執行修改密碼就能夠了
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';(ALTER等能夠寫成小寫)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; FLUSH PRIVILEGES;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
2.八、mysql配置文件
linux版本是my.cnf,通常會放在/etc/my.cnf,/etc/mysql/my.cnf
win下的是my.ini,通常會在安裝目錄的根目錄
但,我在/etc/或者/etc/mysql下也沒找到my.cnf。
在這裏找到了:
[root@target_pc etc]# find / -name my.cnf
/usr/my.cnf
咱們注意到,這裏只說了修改 my.cnf,並無說清楚其絕對路徑是哪一個文件。也就是說,有可能修改的不是正確路徑下的my.cnf文件。
在MySQL中,是容許存在多個 my.cnf 配置文件的,有的能對整個系統環境產生影響,例如:/etc/my.cnf。有的則只能影響個別用戶,例如:~/.my.cnf。
MySQL讀取各個my.cnf配置文件的前後順序是:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
其餘自定義路徑下的my.cnf,例如:/data/mysql/yejr_3306/my.cnf
不論是mysqld服務器端程序,仍是mysql客戶端程序,均可以採用下面兩個參數來自行指定要讀取的配置文件路徑:
-defaults-file=#, 只讀取指定的文件(再也不讀取其餘配置文件)
-defaults-extra-file=#, 從其餘優先級更高的配置文件中讀取全局配置後,再讀取指定的配置文件(有些選項能夠覆蓋掉全局配置從的設定值)
所以,能夠看到,若是你修改的是非「著名」目錄下的 my.cnf,有可能看起來是不生效的,須要自行指定,或者統一放在 /etc/my.cnf 下,採用多實例的方式來管理便可。
一、 開啓mysql的binlog功能
開啓binlog,而且將binlog的格式改成Row,這樣就能夠獲取到CURD的二進制內容,
windows上的路徑爲:C:\ProgramData\MySQL\MySQL Server 5.7\my.ini。
linux上的路徑爲:/etc/my.cnf
[mysqld] #請放在[mysqld]下面,不然不生效 log-bin=mysql-bin #添加這一行就ok binlog-format=ROW #選擇row模式 server_id=1
二、驗證binlog是否開啓
使用命令驗證,而且開啓binlog的過時時間爲30天,默認狀況下binlog是不過時的,這就致使你的磁盤可能會爆滿,直到掛掉。
show variables like 'log_%';
log_bin | ON
三、設置binlog的有效期:
#設置binlog的過時時間爲30天 mysql> show variables like '%expire_logs_days%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 0 | +------------------+-------+ 1 row in set (0.00 sec) mysql> set global expire_logs_days=30; Query OK, 0 rows affected (0.00 sec) mysql>
4、錯誤信息
錯誤信息1 :ERROR 1045 (28000): Access denied for user 'usera'@'localhost' (using password:YES)
錯誤信息2 :ERROR 1045 (28000): Access denied for user 'usera'@'localhost' (using password:NO)
mysql> show grants for 'root'@'localhost'; +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> select user,host from mysql.user; +-------+-----------------------+ | user | host | +-------+-----------------------+ | canal | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | localhost.localdomain | | root | localhost.localdomain | +-------+-----------------------+ 7 rows in set (0.01 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> show grants for 'root'@'%'; +--------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@% | +--------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION | +--------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select user,host,password from mysql.user; +-------+-----------------------+-------------------------------------------+ | user | host | password | +-------+-----------------------+-------------------------------------------+ | root | localhost | | | root | localhost.localdomain | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | localhost.localdomain | | | canal | % | *E3619321C1A937C46A0D8BD1DAC39F93B27D4458 | | root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | +-------+-----------------------+-------------------------------------------+ 8 rows in set (0.00 sec) mysql>