您好,登錄后才能下訂單哦!
[root@localhost ~]# yum install -y \ ##安裝環境組件
> ncurses \
> ncurese-devel \ ##控制終端屏幕顯示的庫
> cmake \ ##cmake工具
> bison ##語法分析
[root@localhost ~]# useradd -s /sbin/nologin mysql ##創建程序用戶
[root@localhost ~]# cd /mnt
[root@localhost mnt]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt ##解壓源碼包到/opt
[root@localhost mnt]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20 nginx-1.12.2 rh
[root@localhost opt]# cd mysql-5.7.20/ ##切換到MySQL目錄下
[root@localhost mysql-5.7.20]# cmake \ ##cmake配置
-DCMAKE_INSTALL_PREFIX=/usr/localmysql \ ##安裝路徑
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ ##定義sock文件連接數據庫文件
-DSYSCONFDIR=/etc \ ##配置文件目錄
-DSYSTEMD_PID_DIR=/usr/local/mysql \ ##PID文件目錄
-DDEFAULT_CHARSET=utf8 \ ##指定字符集
-DDEFAULT_COLLATION=utf8_general_ci \ ##指定字符集默認
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ ##存儲引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \ ##數據庫數據文件目錄
-DWITH_BOOST=boost \ ##底層運行庫
-DWITH_SYSTEMD=1 ##主從參數
》
[root@localhost mysql-5.7.20]# make ##編譯
[root@localhost mysql-5.7.20]# make install ##安裝
[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/ ##數據庫目錄進行權限調整
[root@localhost mysql-5.7.20]# vim /etc/my.cnf ##調整配置文件
[client] ##客戶端
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql] ##客戶端
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld] ##服務器
user = mysql ##用戶
basedir = /usr/local/mysql ##設置mysql的安裝目錄
datadir = /usr/local/mysql/data ##設置mysql數據庫的數據的存放目錄
port = 3306 ##設置3306端口
character_set_server=utf8 ##中文字符集
pid-file = /usr/local/mysql/mysqld.pid ##pid文件路徑
socket = /usr/local/mysql/mysql.sock ##sock文件路徑
server-id = 1 ##主從參數
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
##支持模塊
>
[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf ##給配置文件mysql屬主屬組
[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
##將MySQL寫到本地環境配置中
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile ##設置全局環境配置
[root@localhost mysql-5.7.20]# source /etc/profile ##重啟配置文件
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \ ##初始化
> --user=mysql \ ##用戶
> --basedir=/usr/local/mysql \ ##安裝目錄
> --datadir=/usr/local/mysql/data ##數據庫數據文件目錄
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
##便于systemctl管理
[root@localhost mysql]# systemctl enable mysqld ##開機自啟動
[root@localhost mysql]# systemctl start mysqld.service ##開啟數據庫
[root@localhost mysql]# netstat -ntap | grep 3306 ##查看MySQL端口號開啟情況
tcp6 0 0 :::3306 :::* LISTEN 59464/mysqld
[root@localhost mysql]# mysqladmin -u root -p password
Enter password: ##空格
New password: ##新密碼
Confirm new password: ##確認密碼
mysql> grant all privileges on *.* to 'root'@'%' identified by '123123'; ##提權用戶
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create database test; ##創建數據庫test
Query OK, 1 row affected (0.00 sec)
mysql> show databases; ##查看數據庫
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> use test; ##使用數據庫test
Database changed
mysql> create table info( ##創建表
-> id int(3) not null,
-> name varchar(4) not null,
-> score decimal default 0,
-> primary key (id));
mysql> desc info; ##查看表結構
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| id | int(3) | NO | PRI | NULL | |
| name | varchar(4) | NO | | NULL | |
| score | decimal(10,0) | YES | | 0 | |
+-------+---------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> insert into info values (1,'周幾輪',90); ##往表中插入數據
Query OK, 1 row affected (0.01 sec)
mysql> insert into info values (2,'王峰',default);
Query OK, 1 row affected (0.00 sec)
mysql> insert into info values (3,'娜英',60);
Query OK, 1 row affected (0.00 sec)
mysql> select * from info; ##查看表中的數據
+----+-----------+-------+
| id | name | score |
+----+-----------+-------+
| 1 | 周幾輪 | 90 |
| 2 | 王峰 | 0 |
| 3 | 娜英 | 60 |
+----+-----------+-------+
3 rows in set (0.00 sec)
mysql> update info set score=88 where id=2; ##修改表中的數據
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from info;
+----+-----------+-------+
| id | name | score |
+----+-----------+-------+
| 1 | 周幾輪 | 90 |
| 2 | 王峰 | 88 |
| 3 | 娜英 | 60 |
+----+-----------+-------+
3 rows in set (0.00 sec)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。