系統版本說明 [root@db01 data]# uname -r 3.10.0-693.el7.x86_64 [root@db01 data]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LI ...
系統版本說明
[root@db01 data]# uname -r 3.10.0-693.el7.x86_64 [root@db01 data]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"View Code
1.下載源碼包
下載地址:https://downloads.mysql.com/archives/community/1 yuminstall -y lrzsz #解決依賴
2.解壓數據包
1 mkdir -p /server/tools #創建壓縮包存放位置 2 cd /server/tools 3 rz -y #上傳資料庫包 4 tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz #解壓文件 5 mkdir -p /application/mysql-5.7.17 #創建目錄 6 cd mysql-5.7.17-linux-glibc2.5-x86_64 7 mv * /application/mysql-5.7.17/ #移動文件 8 mkdir -p /application/mysql-5.7.17/data #創建數據存儲目錄 9 chown -R mysql.mysql /application/mysql-5.7.17/data #授權
3.初始化資料庫
1 /application/mysql-5.7.17/bin/mysqld --initialize --basedir=/application/mysql-5.7.17 --datadir=/application/mysql-5.7.17/data/ --user=mysql查看密碼並保存
root@localhost: T9j27b<Po(.E
4.修改配置文件
1 cd /application/mysql-5.7.17/support-files #進入配置目錄 2 vim my.conf #編輯配置文件 3 # 4 [mysqld] 5 user=mysql 6 basedir=/application/mysql-5.7.17 7 datadir=/application/mysql-5.7.17/data 8 socket=/application/mysql-5.7.17/db01.sock 9 log-error=/var/log/mysql-5.7.17.log 10 pid=/application/mysql-5.7.17/db01.pid 11 port=3306 12 [mysql] 13 socket=/application/mysql-5.7.17/db01.sock
1 touch /application/mysql-5.7.17/db01.pid #創建文件 2 sed -i 's#/usr/local/mysql#/application/mysql-5.7.17#g' /application/mysql-5.7.17/bin/mysqld_safe /application/mysql-5.7.17/support-files/mysql.server #替換文件
5.啟動服務
chown -R mysql.mysql /application/mysql-5.7.17 #授權 /application/mysql-5.7.17/support-files/mysql.server start #啟動服務
6.連接服務
1 mysql -uroot -p'T9j27b<Po(.E'
/application/mysql-5.7.17/bin/mysqladmin -uroot -pT9j27b<Po(.E password #使用初始密碼修改密碼 #mysqladmin: [Warning] Using a password on the command line interface can be #insecure. #New password: root 測試密碼為root #Confirm new password: root 測試密碼為root #Warning: Since password will be sent to server in plain text, use ssl connection #to ensure password safety.
7.查看用戶
8.遠程連接資料庫
mysql> grant all on *.* to 'root'@'10.0.0.%' identified by 'root';
測試連接資料庫
1 create DATABASE IF NOT EXISTS test; 2 use test; 3 create table IF NOT EXISTS t1( 4 id int(11) NOT NULL AUTO_INCREMENT, 5 name CHAR(20) NOT NULL UNIQUE , 6 age INT(3) NOT NULL , 7 sex SMALLINT NOT NULL , 8 comments char(50) NOT NULL , 9 PRIMARY KEY(id) 10 )engine=innodb CHARSET=utf8; 11 desc test.t1;View Code
插入上面的代碼併在pycharm中查看表結構