下面一起來了解下MySQL安裝的簡單教程,相信大家看完肯定會受益匪淺,文字在精不在多,希望MYSQL安裝的簡單教程這篇短內容是你想要的。
成都創(chuàng)新互聯(lián)專注于企業(yè)全網營銷推廣、網站重做改版、進賢網站定制設計、自適應品牌網站建設、H5網站設計、成都商城網站開發(fā)、集團公司官網建設、成都外貿網站制作、高端網站制作、響應式網頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為進賢等各大城市提供網站開發(fā)制作服務。
root@localhost ~]# mysql -uroot -p
Enter password:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db2 |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db
MariaDB [mysql]> select user from user;
+------+
| user |
+------+
| lee |
| root |
| root |
| root |
+------+
4 rows in set (0.00 sec)
MariaDB [mysql]> select * from user;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
MariaDB [mysql]> desc user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N
yum install -y mariadb-server
systemctl start mariadb
mysql
netstat -antlpe | grep mysql
vim /etc/my.cnf
[mysqld]模塊下添加
skip-networking=1 ##關閉數據庫在網絡上開啟的端口,加鎖 防止別人進攻 這是端口看不到了
systemctl restart mariadb
netstat -antlpe | grep mysql
mysql
mysql_secure_installation 設置密碼 匿名用戶不能登陸 遠程不能登陸等
mysql -uroot -p
redhat 密碼
MariaDB [(none)]> create database westos;
Query OK, 1 row affected (0.00 sec)
MariaDB [westos]> create table linux(
-> username varchar(15) not null,
-> password varchar(15) not null
-> );
Query OK, 0 rows affected (0.04 sec)
MariaDB [westos]> show tables;
+------------------+
| Tables_in_westos |
+------------------+
| linux |
+------------------+
1 row in set (0.00 sec)
MariaDB [westos]> insert into linux values ('user1','123');
Query OK, 1 row affected (0.01 sec)
MariaDB [westos]> insert into linux values ('user2',password('123'));
Query OK, 1 row affected, 1 warning (0.04 sec) 對密碼進行加密
MariaDB [westos]> select * from linux;
+----------+-----------------+
| username | password |
+----------+-----------------+
| user1 | 123 |
| user2 | *23AE809DDACAF9 |
+----------+-----------------+
2 rows in set (0.00 sec)
MariaDB [westos]> update linux set password=password('234') where username='user1';
Query OK, 1 row affected, 1 warning (0.61 sec)
Rows matched: 1 Changed: 1 Warnings: 1
MariaDB [westos]> delete from linux where username='user1';
Query OK, 1 row affected (0.02 sec)
MariaDB [westos]> alter table linux add age varchar(4);
Query OK, 1 row affected (0.11 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [westos]> select * from linux;
+----------+-----------------+------+
| username | password | age |
+----------+-----------------+------+
| user2 | *23AE809DDACAF9 | NULL |
+----------+-----------------+------+
1 row in set (0.00 sec)
MariaDB [westos]> alter table linux drop age;
Query OK, 1 row affected (0.40 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [westos]> select * from linux;
+----------+-----------------+
| username | password |
+----------+-----------------+
| user2 | *23AE809DDACAF9 |
+----------+-----------------+
1 row in set (0.00 sec)
MariaDB [westos]> alter table linux add age varchar(5) after username;
Query OK, 1 row affected (0.10 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [westos]> select * from linux;
+----------+------+-----------------+
| username | age | password |
+----------+------+-----------------+
| user2 | NULL | *23AE809DDACAF9 |
MariaDB [westos]> alter table linux drop age;
MariaDB [westos]> delete from linux where username='user1';
Query OK, 0 rows affected (0.00 sec)
MariaDB [westos]> drop table linux;
Query OK, 0 rows affected (0.32 sec)
MariaDB [westos]> drop database westos;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db2 |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
Query OK, 1 row affected (0.41 sec)
[root@localhost ~]# mysqldump -u root -predhat westos
[root@localhost ~]# mysqldump -u root -predhat westos > /mnt/westos.sql
[root@localhost ~]# mysql -uroot -predhat -e "drop database westos;"
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db2 |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)
MariaDB [(none)]> mysql -uroot -predhat -e "create database westos;"
-> Ctrl-C -- exit!
Aborted
[root@localhost ~]# mysql -uroot -predhat -e "create database westos;"
[root@localhost ~]# mysql -uroot -predhat westos< /mnt/westos.sql
[root@localhost ~]# mysql -uroot -predhat -e "select * from westos.linux;"
+----------+----------+
| username | password |
+----------+----------+
| user1 | 123 |
| user2 | 456 |
+----------+----------+
MariaDB [(none)]> create user lee@localhost identified by 'lee';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant insert,update,delete,select on westos.linux to lee@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant select on westos.* to lee@'%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show grants for lee@'%';
+----------------------------------------------------------------------------------------------------+
| Grants for lee@% |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'lee'@'%' IDENTIFIED BY PASSWORD '*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96' |
| GRANT SELECT ON `westos`.* TO 'lee'@'%' |
+----------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> revoke delete on westos.linux from lee@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user lee@'localhost';
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# mysqladmin -uroot -pwestos password redhat
[root@localhost ~]# systemctl stop mariadb.service
[root@localhost ~]# ps aux | grep mysql
root 5724 0.0 0.0 112640 980 pts/1 S+ 01:53 0:00 grep --color=auto mysql
[root@localhost ~]# mysqld_safe --skip-grant-tables &
[1] 5744
[root@localhost ~]# killall -9 mysqld_safe
[1]+ Killed mysqld_safe --skip-grant-tables
[root@localhost ~]# ps aux | grep mysql
[root@localhost ~]# kill -9 6019
[root@localhost ~]# ps aux | grep mysql
root 6083 0.0 0.0 112640 980 pts/1 R+ 02:02 0:00 grep --color=auto mysql
[root@localhost ~]# systemctl start mariadb
@@@@@@@@@@ 用網頁 鼠標點一點便可建立數據庫 插入表 刪除表數據庫等等
lftp 172.25.254.250:/pub/docs/software> get phpMyAdmin-3.4.0-all-languages.tar.bz2
4548030 bytes transferred
lftp 172.25.254.250:/pub/docs/software> quit
[root@localhost ~]# ls
anaconda-ks.cfg lala.py Public
backup.dump linux.dump Templates
Desktop Music Videos
Documents phpMyAdmin-3.4.0-all-languages.tar.bz2 westos.dump
Downloads Pictures
[root@localhost ~]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/
[root@localhost ~]# ls
anaconda-ks.cfg lala.py Public
backup.dump linux.dump Templates
Desktop Music Videos
Documents phpMyAdmin-3.4.0-all-languages.tar.bz2 westos.dump
Downloads Pictures
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
phpMyAdmin-3.4.0-all-languages
[root@localhost html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
ot@localhost html]# ls
mysqladmin
[root@localhost html]# cd mysqladmin/
[root@localhost mysqladmin]# ls
browse_foreigners.php main.php server_status.php
bs_disp_as_mime_type.php navigation.php server_synchronize.php
bs_play_media.php phpdoctor.ini server_variables.php
........
[root@localhost mysqladmin]# cp -p config.sample.inc.php config.inc.php
[root@localhost mysqladmin]# vim config.inc.php
17 $cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
[root@localhost mysqladmin]# systemctl restart httpd
測試:
訪問 http://172.25.254.170/mysqladmin
這是會看到phpMyAdmin 界面 這個時候選擇中文root redhat
可以新建數據庫 表 插入 刪除表 等等
################ mysql ######################################
數據庫時有好多張表組成
yum install -y mariadb-server
systemctl start mariadb
mysql
netstat -antlpe | grep mysql 會看到3306端口
vim /etc/my.cnf
[mysqld]模塊下添加
skip-networking=1 ##關閉數據庫在網絡上開啟的端口,加鎖 防止別人進攻 這是端口看
不到了 這樣別人就不能***修改數據庫上的數據了 1表有效
systemctl restart mariadb
netstat -antlpe | grep mysql 這時看不到3306端口了
mysql_secure_installation 設置root密碼 匿名用戶不能登陸 遠程不能登陸
mysql -uroot -p
redhat 輸入mysql的密碼
@@@@@@@@@@@@ 數據庫的基本sql語句操作 @@@@@@@@@@@@@@@@
1 登陸
mysql -uroot -predhat
2 查詢
show databases; 顯示數據庫
use mysql; 進入mysql數據庫
show tables; 顯示當前庫中表的名稱
select * from user; 查詢user表中的所有內容(*可以用此表中的任何字段表示)
desc user; 查詢user表的結構(顯示所有字段的名稱)
3數據庫及表的建立
create database westos 創(chuàng)建westos庫
create table linux( 創(chuàng)建linux表 并且linux表含有兩個字段username password
username varchar(15) not null, username字段 字符長度最大15個,并且不能為空
password varchar(15) not null
);
insert into linux values ('user1','123'); 向linux表中插入數據,username字段的數據為user1
insert into linux values ('user2',password('123')); 插入password字段的數據是用password加密過的
4更新數據庫信息
update linux set password=password('passwd2') where username='user1';
更新user1的密碼
delete from linux where username='user1'; 刪除user1信息
alter table linux add age varchar(4); 添加age字段到linux表的最后一列
alter table linux add age varchar(5) after name; 添加age字段在name字段之后
alter table linux drop age; 刪除age字段
5刪除數據庫
delete from linux where username='user1'; 刪除user1的數據從linux表中
drop table linux; 刪除linux表
drop database westos; 刪除westos數據庫
6 數據庫的備份
mysqldump -u root -predhat --all-database 備份所有表中的所有數據
mysqldump -u root -predhat --all-database --no-database --no-data 備份所有表但不備份數據
mysqldump -u root -predhat westos 備份westos數據庫
mysqldump -u root -predhat westos > /mnt/westos.sql
備份westos數據庫并把數據保存到westos.sql中
mysqldump -u root -predhat westos linux > /mnt/linux.sql
備份mysql中的linux表
mysql -uroot -predhat -e "create database westos;" 建立westos庫
mysql -uroot -predhat westos < /mnt/westos.sql 把數據導入westos庫
7用戶授權 必須用超級用戶
create user lee@localhost identified by 'lee'; 建立用戶lee,此用戶只能通過本機登陸
create user lee@'%' identified by 'lee'; 建立用戶lee,此用戶可以通過網絡登錄
grant insert,update,delect,select on westos.test to lee@localhost;
用戶授權 授權westos數據庫的test表可以通過localhost主機登陸lee用戶
grant select on westos.* to lee@'%';
show grants for lee@'%' 查看用戶授權
show grants for lee@localhost
revoke delete on westos.test from lee@localhost; 去除用戶授權權力
drop user lee@'%'; 刪除用戶
8修改密碼
mysqladmin -uroot -predhat password lee
忘記超級用戶密碼時的操作
mysqld_safe --skip-grant-tables & 開啟mysql登陸接口并忽略授權表
mysql 直接不用密碼可以登陸
update mysql.user set Password=password('123') where User='root';
更新超級用戶密碼信息
ps aux | grep mysql 過濾mysql的所有進程并結束這些進程
kill -9 mysqlpid
systemctl start mariadb 重新開啟mysql
mysql -uroot -p123 登陸測試
1安裝
yum install -y httpd php php-mysql
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
下載 phpMyAdmin-3.4.0-all-languages.tar.bz2
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html解壓到指定目錄
cd /var/www/html
mv phpMyAdmin-3.4.0-all-languages mysqladmin
cd mysqladmin
cp -p config.sample.inc.php config.inc.php
vim config.inc.php
17 $cfg['blowfish_secret']= 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIEAUTH! */
systemctl restrt httpd
測試:
訪問http://172.25.254.170/mysqladmin
會看到phpadmin界面 用鼠標點一點即可創(chuàng)建數據庫 添加字段 刪除表等 同時還會同步到命令行中 用命令可以在命令行中看到 相當于用命令創(chuàng)建 刪除增添 但是phpmyadmin方便快捷
看完MYSQL安裝的簡單教程這篇文章后,很多讀者朋友肯定會想要了解更多的相關內容,如需獲取更多的行業(yè)信息,可以關注我們的行業(yè)資訊欄目。
當前名稱:MYSQL安裝的簡單教程
新聞來源:http://aaarwkj.com/article38/igjppp.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供網站內鏈、小程序開發(fā)、網站排名、品牌網站建設、標簽優(yōu)化、網站設計公司
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)