------------------------------------------------------------------- CentOS8 安裝及基本設定
VMware-player-15.5.1-15018445.exe
CentOS-8.1.1911-x86_64-dvd1.iso
setup!
# uname -r
4.18.0-147.el8.x86_64 //核心版本:4.18.0 已經修改 147次 x86相容電腦i686 64位元
# w //列出目前登入使用者資訊
23:10:19 up 1 min, 1 user, load average: 0.18, 0.10, 0.04
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.2.100 23:09 1.00s 0.04s 0.01s w
# date
一 2月 17 23:16:37 CST 2020
zh_TW.UTF-8
# locale
LANG=zh_TW.UTF-8
LC_CTYPE="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_COLLATE="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_MESSAGES="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"
LC_ALL=
# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:67:87:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.2.103/24 brd 192.168.2.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::738b:2e41:1d4b:20f3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# nmtui
Network Manager:
編輯連線
啟用連線
設定系統主機名稱
Network Manager:
編輯連線
啟用連線
設定系統主機名稱
# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="9cb77588-c78e-40b0-acbe-3be164c3e385"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.2.103"
PREFIX="24"
GATEWAY="192.168.2.1"
DNS1="192.168.2.1"
IPV6_PRIVACY="no"
# systemctl restart NetworkManager.service
# yum -y update
---------------------------------------------- hostnamectl
//hostnamectl 取替 hostname
# hostnamectl set-hostname CentOS8.Ku
# hostnamectl
Static hostname: CentOS8.Ku
Icon name: computer-vm
Chassis: vm
Machine ID: 964572b3e4d64c338b0bc8c066ac099c
Boot ID: 1c016fbe42b8401d84e934a75a3a450e
Virtualization: vmware
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-147.5.1.el8_1.x86_64
Architecture: x86-64
# vi /etc/hostname
Ku.CentOS8
------------------------------------------------------------------- Linux安裝 Apache, MariaDB, PHP (LAMP)
# yum -y install httpd httpd-tools
# systemctl start httpd
# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
# firewall-cmd --permanent --zone=public --add-service=http //80 port
success
# firewall-cmd --permanent --zone=public --add-service=https //443 port
success
# firewall-cmd --reload
success
# systemctl reload firewalld
http://192.168.2.103/
# yum -y install mariadb-server mariadb
# systemctl start mariadb
# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mari adb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mar iadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /u sr/lib/systemd/system/mariadb.service.
# mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on...
//設定 root 帳號密碼
Set root password? [Y/n] y
New password: //db123456
Re-enter new password:
Password updated successfully!
//是否移除匿名帳號
Remove anonymous users? [Y/n] y
//是否允許 root 帳號遠端登入
Disallow root login remotely? [Y/n] y
//是否移除 test 資料庫
Remove test database and access to it? [Y/n] n
//
Reload privilege tables now? [Y/n] y
# mysql -u root -p
Enter password: //db123456
MariaDB [(none)]> show variables like 'version'; //MariaDB 版本
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| version | 10.3.17-MariaDB |
+---------------+-----------------+
MariaDB [(none)]> show variables like 'version'; //MariaDB 版本
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| version | 10.3.17-MariaDB |
+---------------+-----------------+
MariaDB [(none)]>
Ctrl-C -- exit!
Aborted
# yum -y install php php-fpm php-mysqlnd php-opcache php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
//CentOS 8 的 Apache, 預設使用 PHP-FPM 執行 PHP, 所以需要啟動 PHP-FPM
# systemctl start php-fpm
# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
# systemctl restart httpd
//讓 SELinux 允許 Apache 透過 PHP-FPM 執行 PHP 程式碼:
# setsebool -P httpd_execmem 1
# vi /var/www/html/info.php
<?php
phpinfo();
?>
http://192.168.2.103/info.php
------------------------------------------------------------------- MariaDB
參考資料:
佳魁資訊--更純正開放 MySQL MariaDB 的完全制霸手冊--黃縉華
# mysql -u root -p
Enter password: //db123456
/************ 建立資料庫 表 與刪除 ******************
MariaDB [(none)]> create database dbTest;
MariaDB [(none)]> show databases;
資料庫儲存引擎:
決定 MariaDB 資料庫中的表,可以使用的儲存方式、交易處理方式...等
方法1:
MariaDB [(none)]> show engines\G; // \G 結果顯示較美觀
.
.
*************************** 10. row ***************************
Engine: InnoDB
Support: DEFAULT // MariaDB 是否支援 。預設
Comment: Supports transactions, row-level locking, foreign keys and encryption for tables //評論
Transactions: YES //是否支援交易處理
XA: YES //是否分散式交易處理的 XA 標準
Savepoints: YES //否支援儲存點,以便交易復原到儲存點
MariaDB [(none)]> show variables like 'storage_engine'; //查詢預設儲存引擎
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
MariaDB [dbKu]> show variables like 'character_set%'; //查詢字元集
+--------------------------+------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------+
| character_set_database | latin1
???修改
default storage engine and character_set
???
MariaDB [dbTest]> show create database dbTest\G;
*************************** 1. row ***************************
Database: dbTest
Create Database: CREATE DATABASE `dbTest` /*!40100 DEFAULT CHARACTER SET latin1 */
MariaDB [(none)]> use dbTest;
MariaDB [dbTest]> create table tblStu(sid int primary key auto_increment,na varchar(10));
MariaDB [dbTest]> show tables;
MariaDB [dbTest]> show create table tblStu\G;
*************************** 1. row ***************************
Table: tblStu
Create Table: CREATE TABLE `tblStu` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`na` varchar(10) DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
MariaDB [dbTest]> drop table tblStu;
MariaDB [dbTest]> show tables;
MariaDB [dbTest]> drop database dbTest;
MariaDB [(none)]> show databases;
/************ 建立 資料庫 並設 character set ************
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDB [(none)]> create database dbKu character set='utf8' collate='utf8_unicode_ci';
MariaDB [(none)]> show databases;
//建立 database 即 設定 character set='utf8' collate='utf8_unicode_ci
//新增 表 才能輸入中文 或匯入 表 時中文才不會呈現亂碼
MariaDB [dbKu]> show engines\G;
.
.
*************************** 10. row ***************************
Engine: InnoDB
Support: DEFAULT
Comment: Supports transactions, row-level locking, foreign keys and encryption for tables
Transactions: YES
XA: YES
Savepoints: YES
.
.
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.001 sec)
MariaDB [dbKu]> show variables like 'character%';
+--------------------------+------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
.
.
MariaDB [dbKu]> show create database dbKu\G;
*************************** 1. row ***************************
Database: dbKu
Create Database: CREATE DATABASE `dbKu` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */
/****************** 建立 表 ************
MariaDB [dbKu]> create table tblStu (sid int primary key auto_increment, gra varchar(1), cla varchar(2), sno varchar(2), na varchar(10), pwd varchar(10));
MariaDB [dbKu]> show tables;
# ls /var/lib/mysql/dbKu/ // MariaDB 安裝資料夾
db.opt tblStu.frm tblStu.ibd
MariaDB [dbKu]> describe tblStu;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| sid | int(11) | NO | PRI | NULL | auto_increment |
| gra | varchar(1) | YES | | NULL | |
| cla | varchar(2) | YES | | NULL | |
| sno | varchar(2) | YES | | NULL | |
| na | varchar(10) | YES | | NULL | |
| pwd | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
MariaDB [dbKu]> show create table tblStu\G;
*************************** 1. row ***************************
Table: tblStu
Create Table: CREATE TABLE `tblStu` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`gra` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`cla` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`sno` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`na` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`pwd` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
/****************** 表 資料編輯******************
MariaDB [dbKu]> insert into tblStu(gra,cla,sno,na,pwd)values('1','12','40','李大明','123456');
MariaDB [dbKu]> select * from tblStu;
MariaDB [dbKu]> update tblStu set pwd='2222222222' where sid=2;
MariaDB [dbKu]> select * from tblStu;
MariaDB [dbKu]> delete from tblStu where sid=2;
MariaDB [dbKu]> select * from tblStu;
/****************** 備份與還原******************
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#mysqldump -u username -p db [tbl1 tbl2 ...] > BK.sql
#ls /var/lib/mysql/dbKu/
#mysql -u username -p db < BK.sql
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.備份還原 資料表 /////////////////////
# mysqldump -u root -p dbKu tblStu > dbKu_tblStu_BK.sql;
Enter password: //db123456
# ls //root 身分執行
dbKu_tblStu_BK.sql
# cat dbKu_tblStu_BK.sql //看備份內容
MariaDB [dbKu]> drop table tblStu;
MariaDB [dbKu]> show tables;
# ls /var/lib/mysql/dbKu/ //MariaDB 安裝資料夾內已沒有 tblStu 資料
db.opt
Enter password:
MariaDB [(none)]> use dbKu;
MariaDB [dbKu]> show tables;
MariaDB [dbKu]> show create table tblStu\G; //確認 character set
2.備份還原 資料庫 /////////////////////
Enter password:
ls
anaconda-ks.cfg dbKu_BK.sql dbKu_tblStu_BK.sql
###### 移除資料庫 再重建立一新資料庫(也可以與原來資料庫不同名),再還原
MariaDB [(none)]> drop database dbKu;
MariaDB [(none)]> show databases;
# ls /var/lib/mysql/
MariaDB [(none)]> create database dbKu character set='utf8' collate='utf8_unicode_ci';
MariaDB [(none)]> show databases;
MariaDB [(none)]> show create database dbKu\G;
# mysql -u root -p dbKu < dbKu_BK.sql
Enter password:
MariaDB [(none)]> use dbKu;
MariaDB [dbKu]> show tables;
MariaDB [dbKu]> select * from tblStu;
MariaDB [dbKu]> show create table tblStu\G;
/****************** 表 匯出與匯入******************
匯出 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
方法1: MariaDB 內
select fieldNa from TableNa [where ...] into outfile 'outNa.txt' [option];
option:
fields terminated by '字串' //設定欄位分隔符號,預設 '\t'
MariaDB [dbKu]> select * from tblStu into outfile './tblStu.txt'; // ./ 表 MariaDB 安裝目錄
# ls /var/lib/mysql
tblStu.txt
MariaDB [dbKu]> select * from tblStu into outfile 'tblStu.txt'; //沒寫 自己的 db 資料夾內
# ls /var/lib/mysql/dbKu
db.opt tblStu.frm tblStu.ibd tblStu.txt
方法2:
#mysqldump -u root -p -T db table --目標目錄 [option]
# mysqldump -u root -p -t dbKu tblStu --tab=./
Enter password:
mysqldump: Got error: 1: "Can't create/write to file '/root/tblStu.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
???????
# mysqldump -u root -p -t dbKu tblStu --tab=/var/lib/mysql/dbKu;
Enter password:
# ls /var/lib/mysql/dbKu/
db.opt tblStu.frm tblStu.ibd tblStu.sql tblStu.txt
1 1 12 40 李大明 123456
8 2 13 35 趙無級 2222222
9 3 16 22 王小咪 33333333
11 1 12 40 李大明 123456
12 1 12 37 馬久久 66666
方法3:
mysql -u root -p -e "select ..." dbNa > ./bkNa.txt
# mysql -u root -p -e "select * from tblStu" dbKu > ./stu.txt
Enter password:
# ls
anaconda-ks.cfg dbKu_BK.sql dbKu_tblStu_BK.sql stu.txt
# cat stu.txt
sid gra cla sno na pwd
1 1 12 40 李大明 123456
8 2 13 35 趙無級 2222222
9 3 16 22 王小咪 33333333
11 1 12 40 李大明 123456
12 1 12 37 馬久久 66666
匯入 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
方法1: MariaDB 內
load data [local] infile file into tblNa [option]
local:本機電腦中文字檔
option:fields terminated by '字串' // 設定欄位分隔符號,預設 '\t'
# vi /var/lib/mysql/dbKu/tblStu.txt
21 1 12 40 陳名曲 123456
22 2 13 35 蔡不通 2222222
MariaDB [dbKu]> load data infile 'tblStu.txt' into table tblStu;
MariaDB [dbKu]> select * from tblStu;
方法2:
mysqlimport -u root -p [--local] dbNa file [option]
local:本機電腦中文字檔
file:文字檔的路徑和名稱
option:--field-terminated-by=字串 // 設定欄位分隔符號,預設 '\t'
# vi /var/lib/mysql/dbKu/tblStu.txt
33 1 12 40 韓有說 123456
# mysqlimport -u root -p dbKu 'tblStu.txt'
Enter password:
MariaDB [(none)]> use dbKu;
MariaDB [dbKu]> select * from tblStu;
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MariaDB [dbKu]> select * from tblStu into outfile 'tblStu.txt';
# ls /var/lib/mysql/dbKu/
db.opt tblStu.frm tblStu.ibd tblStu.txt
//新增資料再匯入
# vi /var/lib/mysql/dbKu/tblStu.txt
11 1 12 40 李大明 123456
8 2 13 35 趙無級 2222222
9 3 16 22 王小咪 33333333
8 2 13 35 趙無級 2222222
9 3 16 22 王小咪 33333333
MariaDB [(none)]> use dbKu;
MariaDB [dbKu]> load data infile 'tblStu.txt' into table tblStu;
MariaDB [dbKu]> select * from tblStu;
MariaDB [dbKu]> insert into tblStu(gra,cla,sno,na,pwd)values('1','12','37','馬久久','66666');
MariaDB [dbKu]> select * from tblStu;
+-----+------+------+------+-----------+----------+
| sid | gra | cla | sno | na | pwd |
+-----+------+------+------+-----------+----------+
| 1 | 1 | 12 | 40 | 李大明 | 123456 |
| 8 | 2 | 13 | 35 | 趙無級 | 2222222 |
| 9 | 3 | 16 | 22 | 王小咪 | 33333333 |
| 11 | 1 | 12 | 40 | 李大明 | 123456 |
| 12 | 1 | 12 | 37 | 馬久久 | 66666 |
+-----+------+------+------+-----------+----------+
/****************** 資料表 相關操作 ******************
MariaDB [dbKK]> create table tblStu(sid int primary key auto_increment,na varchar(10) not null);
MariaDB [dbKK]> show tables;
/****** 檢視 表 結構
方法1:
MariaDB [dbKK]> describe tblStu\G;
/****** 檢視 表 結構
方法1:
MariaDB [dbKK]> describe tblStu\G;
方法2:較完整
MariaDB [dbKK]> show create table tblStu\G;
/****** 改 表 名 : 舊 rename 新
MariaDB [dbKK]> alter table tblStu rename tblUser;
/****** 新增欄位
MariaDB [dbKK]> alter table tblUser add phone varchar(10);
MariaDB [dbKK]> describe tblUser;
/****** modify 只能修改欄位 資料類型
MariaDB [dbKK]> alter table tblUser modify na varchar(20);
MariaDB [dbKK]> describe tblUser;
/****** change 可以 同時 修改 欄位名 及 資料類型,或只修改其中一項
MariaDB [dbKK]> alter table tblUser change na name varchar(15);
MariaDB [dbKK]> describe tblUser;
/****** 欄位移到第1個位置
MariaDB [dbKK]> alter table tblUser modify UserNa varchar(20) first;
MariaDB [dbKK]> show create table tblUser\G;
/****** 欄位移到指定位置之後
MariaDB [dbKK]> alter table tblUser modify UserNa varchar(20) after sid;
MariaDB [dbKK]> show create table tblUser\G;
/****** 刪除欄位
MariaDB [dbKK]> alter table tblUser drop phone;
MariaDB [dbKK]> show create table tblUser\G;
/****** 修改 表 的儲存引擎
MariaDB [dbKK]> alter table tblUser engine=MyISAM;
MariaDB [dbKK]> show create table tblUser\G;
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------
沒有留言:
張貼留言