您好,登錄后才能下訂單哦!
下面一起來了解下MYSQL安裝的簡單教程,相信大家看完肯定會受益匪淺,文字在精不在多,希望MYSQL安裝的簡單教程這篇短內(nèi)容是你想要的。
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 ##關(guān)閉數(shù)據(jù)庫在網(wǎng)絡(luò)上開啟的端口,加鎖 防止別人進(jìn)攻 這是端口看不到了
systemctl restart mariadb
netstat -antlpe | grep mysql
mysql
mysql_secure_installation 設(shè)置密碼 匿名用戶不能登陸 遠(yuǎn)程不能登陸等
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) 對密碼進(jìn)行加密
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
@@@@@@@@@@ 用網(wǎng)頁 鼠標(biāo)點(diǎn)一點(diǎn)便可建立數(shù)據(jù)庫 插入表 刪除表數(shù)據(jù)庫等等
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 界面 這個時(shí)候選擇中文 root redhat
可以新建數(shù)據(jù)庫 表 插入 刪除表 等等
################ mysql ######################################
數(shù)據(jù)庫時(shí)有好多張表組成
yum install -y mariadb-server
systemctl start mariadb
mysql
netstat -antlpe | grep mysql 會看到3306端口
vim /etc/my.cnf
[mysqld]模塊下添加
skip-networking=1 ##關(guān)閉數(shù)據(jù)庫在網(wǎng)絡(luò)上開啟的端口,加鎖 防止別人進(jìn)攻 這是端口看
不到了 這樣別人就不能***修改數(shù)據(jù)庫上的數(shù)據(jù)了 1表有效
systemctl restart mariadb
netstat -antlpe | grep mysql 這時(shí)看不到3306端口了
mysql_secure_installation 設(shè)置root密碼 匿名用戶不能登陸 遠(yuǎn)程不能登陸
mysql -uroot -p
redhat 輸入mysql的密碼
@@@@@@@@@@@@ 數(shù)據(jù)庫的基本sql語句操作 @@@@@@@@@@@@@@@@
1 登陸
mysql -uroot -predhat
2 查詢
show databases; 顯示數(shù)據(jù)庫
use mysql; 進(jìn)入mysql數(shù)據(jù)庫
show tables; 顯示當(dāng)前庫中表的名稱
select * from user; 查詢user表中的所有內(nèi)容(*可以用此表中的任何字段表示)
desc user; 查詢user表的結(jié)構(gòu)(顯示所有字段的名稱)
3數(shù)據(jù)庫及表的建立
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表中插入數(shù)據(jù),username字段的數(shù)據(jù)為user1
insert into linux values ('user2',password('123')); 插入password字段的數(shù)據(jù)是用password加密過的
4更新數(shù)據(jù)庫信息
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刪除數(shù)據(jù)庫
delete from linux where username='user1'; 刪除user1的數(shù)據(jù)從linux表中
drop table linux; 刪除linux表
drop database westos; 刪除westos數(shù)據(jù)庫
6 數(shù)據(jù)庫的備份
mysqldump -u root -predhat --all-database 備份所有表中的所有數(shù)據(jù)
mysqldump -u root -predhat --all-database --no-database --no-data 備份所有表但不備份數(shù)據(jù)
mysqldump -u root -predhat westos 備份westos數(shù)據(jù)庫
mysqldump -u root -predhat westos > /mnt/westos.sql
備份westos數(shù)據(jù)庫并把數(shù)據(jù)保存到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 把數(shù)據(jù)導(dǎo)入westos庫
7用戶授權(quán) 必須用超級用戶
create user lee@localhost identified by 'lee'; 建立用戶lee,此用戶只能通過本機(jī)登陸
create user lee@'%' identified by 'lee'; 建立用戶lee,此用戶可以通過網(wǎng)絡(luò)登錄
grant insert,update,delect,select on westos.test to lee@localhost;
用戶授權(quán) 授權(quán)westos數(shù)據(jù)庫的test表可以通過localhost主機(jī)登陸lee用戶
grant select on westos.* to lee@'%';
show grants for lee@'%' 查看用戶授權(quán)
show grants for lee@localhost
revoke delete on westos.test from lee@localhost; 去除用戶授權(quán)權(quán)力
drop user lee@'%'; 刪除用戶
8修改密碼
mysqladmin -uroot -predhat password lee
忘記超級用戶密碼時(shí)的操作
mysqld_safe --skip-grant-tables & 開啟mysql登陸接口并忽略授權(quán)表
mysql 直接不用密碼可以登陸
update mysql.user set Password=password('123') where User='root';
更新超級用戶密碼信息
ps aux | grep mysql 過濾mysql的所有進(jìn)程并結(jié)束這些進(jìn)程
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界面 用鼠標(biāo)點(diǎn)一點(diǎn)即可創(chuàng)建數(shù)據(jù)庫 添加字段 刪除表等 同時(shí)還會同步到命令行中 用命令可以在命令行中看到 相當(dāng)于用命令創(chuàng)建 刪除增添 但是phpmyadmin方便快捷
看完MYSQL安裝的簡單教程這篇文章后,很多讀者朋友肯定會想要了解更多的相關(guān)內(nèi)容,如需獲取更多的行業(yè)信息,可以關(guān)注我們的行業(yè)資訊欄目。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。