注 : 有些操做和操做系統有關。mysql
mysql -h localhost -u root -p #### 示例 bovenson@MBP:~/Git/notes/MySQL$ mysql -h localhost -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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>
### Mac sudo /usr/local/mysql/support-files/mysql.server start # 啓動 sudo /usr/local/mysql/support-files/mysql.server stop # 中止 sudo /usr/local/mysql/support-files/mysql.server restart # 重啓
# set password for 用戶名@localhost = password('新密碼'); set password for root@localhost = password('123');
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass'; CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
GRANT ALL ON *.* TO 'myuser'@'localhost'; GRANT ALL ON *.* TO 'myuser'@'%'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # 修改bind-address bind-address = 0.0.0.0
添加/修改帳戶容許的Host
爲%
sql
mysql -u root -p -h 10.154.0.43 -P 3306
默認設置爲CURRENT_TIMESTAMP
shell
Just add below in my.ini
or my.cnf
.vim
[mysqld] skip-name-resolve
# 下載 rpm 源 $ wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm # 安裝 rpm 源 $ yum localinstall mysql57-community-release-el7-11.noarch.rpm # 安裝 MySQL $ yum install mysql-community-server # 啓動 MySQL $ systemctl start mysqld # 開機啓動 $ systemctl enable mysqld $ systemctl daemon-reload # 獲取root密碼 $ cat /var/log/mysqld.log | grep password ... [Note] A temporary password is generated for root@localhost: ... # 登陸mysql $ mysql -u root -p # 輸入獲取到的臨時密碼 # 重置root密碼 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '{password}'; # 新建遠程登陸用戶 mysql> CREATE USER 'root'@'%' IDENTIFIED BY '{password}'; # 受權 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; # 刷新權限 mysql> FLUSH PRIVILEGES; # 防火牆放行3306端口 $ firewall-cmd --zone=public --add-port=3306/tcp --permanent $ firewall-cmd --reload