mysql的安裝和基本操做

系統環境:mysql

CentOS Linux release 7.6.1810 (Core)linux

mysql版本:5.27 下載地址https://dev.mysql.com/downloads/mysql/
[root@server10 mysql7]# ls #下載安裝包並安裝
mysql-community-client-5.7.25-1.el7.x86_64.rpm
mysql-community-common-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm //test
mysql-community-server-5.7.25-1.el7.x86_64.rpm
[root@server10 mysql7]# yum install *
[root@server10 ~]# systemctl start mysqld
[root@server10 mysql]# grep password /var/log/mysqld.log #查看初始密碼sql

[root@server10 mysql7]# ls #下載安裝包並安裝
mysql-community-client-5.7.25-1.el7.x86_64.rpm
mysql-community-common-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm //test
mysql-community-server-5.7.25-1.el7.x86_64.rpm
[root@server10 mysql7]# yum install *
[root@server10 ~]# systemctl start mysqld
[root@server10 mysql]# grep password /var/log/mysqld.log #查看初始密碼數據庫

[root@server10 mysql]# mysql_secure_installation #初始化 #修改root密碼爲含大小寫特殊字符很多於8位的密碼而後一路回車框架

[root@server10 mysql]# mysql -pide

mysql> show databases; #查看庫code

+--------------------+orm

| Database |server

+--------------------+ip

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

mysql> create database westos; #建庫

Query OK, 1 row affected (0.00 sec)

mysql> use westos;

Database changed

mysql> create table linux( #建表

-> user varchar(20) not null,

-> password varchar(20) not null

-> );

Query OK, 0 rows affected (0.01 sec)

mysql> desc linux; #查看錶結構

+----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| user | varchar(20) | NO | | NULL | |

| password | varchar(20) | NO | | NULL | |

+----------+-------------+------+-----+---------+-------+

2 rows in set (0.00 sec)

mysql> insert into linux values ('wo','134'); #插入數據

Query OK, 1 row affected (0.00 sec

mysql> select * from linux; #查看錶

+------+----------+

| user | password |

+------+----------+

| wo | 134 |

+------+----------+

1 row in set (0.00 sec
用戶受權:

mysql> create user guoyanfeng@'%' identified by 'XR@westos123.com'; #建立用戶
Query OK, 0 rows affected (0.00 sec)

mysql> grant select,insert on westos.* to guoyanfeng@'%'; #受權到庫
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for guoyanfeng@'%'; #查看權限

+--------------------------------------------------------+

| Grants for guoyanfeng@% |

+--------------------------------------------------------+

| GRANT USAGE ON . TO 'guoyanfeng'@'%' |

| GRANT SELECT, INSERT ON westos.* TO 'guoyanfeng'@'%' |

+--------------------------------------------------------+

2 rows in set (0.00 sec)

mysql> grant all privileges on . to guoyanfeng@'%'; #用戶全部庫的滿權限

mysql> revoke insert,select on westos.* from guoyanfeng@'%'; #撤銷權限

mysql> show grants for guoyanfeng@'%';

+-------------------------------------------------+

| Grants for guoyanfeng@% |

+-------------------------------------------------+

| GRANT ALL PRIVILEGES ON . TO 'guoyanfeng'@'%' |

+-------------------------------------------------+

mysql> use mysql;

mysql> update mysql.user set authentication_string=password('XR&westos123.com') where user='guoyanfeng' #改用戶密碼

mysql> flush privileges; #刷新

mysqldump -uroot -pwestos--all-databases ##備份全部數據庫

mysqldump -uroot -pwestos --all-database--no-data ##備份全部數據庫框架

[root@server10 ~]# mysqldump -u root -pCaonimei@478 --all-databases > /mnt/all.sql

mysqldump: [Warning] Using a password on the command line interface can be insecure. #備份會報錯但不影響備份,緣由爲mysql版本問題須在my.cnf文件中添加用戶名和密碼執行備份
mysql跳過密碼登陸:

1.在 etc/my.cnf 的 [mysqld] 下添加 skip-grant-tables

2.重啓mysql服務便可.
mysql遇到不可解決的問題時:#慎用

備份全部數據庫,肯定無誤。

[root@server10 mysql]# systemctl stop mysqld.service #中止數據庫

[root@server10 mysql]# cd /var/lib/mysql #默認路徑

[root@server10 mysql]# rm -fr * #刪除全部,從新初始化

相關文章
相關標籤/搜索