centos7安裝mysql數據庫服務

參考文章:html

http://blog.csdn.net/u010246789/article/details/52382632mysql

https://www.cnblogs.com/zhangmingcheng/p/6102366.htmlsql

數據庫服務:沒有數據庫的程序叫頁面而已。會重點講解最流行的開源數據庫Mysql。包括Mysql的安裝、密碼初始化、遠程鏈接、General Log、新建用戶、分配權限、root密碼重置。數據庫

1、mysql的安裝

搜索mysql是否安裝centos

yum search mysqlsession

 

移除mysqlide

yum remove mariadb-libs.x86_64spa

 

去mysql官網找源.net

 

 

 

點擊複製連接就行rest

先移動動臨時文件夾,

cd /tmp 

下載源

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

查看下載的源包 ls

安裝源

yum localinstall  mysql57-community-release-el7-11.noarch.rpm

查詢

yum search mysql   查到社區版的數據庫

安裝

yum install mysql-community-server.x86_64

重啓mysql和查看mysql進程是否存在

service mysqld restart

ps -ef | grep mysql

查看安裝mysql默認密碼

cat /var/log/mysqld.log | grep password

進入mysql

 

進行數據庫操做會報錯,必須修改密碼。

注意:若是隻想設置簡單密碼須要修改兩個全局參數:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

再修改:

mysql> SET PASSWORD = PASSWORD('123456');   //123456 是重置的新密碼

參考 http://blog.sina.com.cn/s/blog_a0d71a9d0102wlz3.html

再退出數據庫

exit命令

再看看能不能從新進入

history  查看歷史操做記錄

2、遠程鏈接

進入數據庫

mysql -h127.0.0.1 root -uroot -p

show databases;  找到mysql數據庫

use mysql; 

show tables 查找user  對其修改受權

select * from user \G;  格式化顯示數據

select Host,User from user \G;  只須要顯示這2個字段數據

update user set host='%' where Host="localhost" and User="root"; 更新受權

再查詢

select Host,User from user \G

mysql> select Host,User from user \G
*************************** 1. row ***************************
Host: %
User: root
*************************** 2. row ***************************
Host: localhost
User: mysql.session
*************************** 3. row ***************************
Host: localhost
User: mysql.sys
3 rows in set (0.00 sec)

刷新權限

flush privileges;

或者另外一種刷新權限方法:退出mysql,重啓

mysql> exit
Bye
[root@VM_0_16_centos ~]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service
[root@VM_0_16_centos ~]#

 

查看防火牆是否啓動

ps -ef | grep firewalld

關閉防火牆

service firewalld stop
而後就能夠遠程鏈接了

3、mysql日誌服務 開啓general_log

指定位置:

mysql> set global general_log_file="/tmp/general.log";
Query OK, 0 rows affected (0.00 sec)

開啓

mysql> set global general_log=on;
Query OK, 0 rows affected (0.00 sec)

建立管理員用戶,並賦予操控全部庫中的數據表權限

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> create user 'user1'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'user1'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

也能夠只賦予select,insert權限

grant select,insert on *.* to 'user1'@'%' identified by '123456' with grant option;

收回全部權限,同時刷新

mysql> revoke all privileges on *.* from user1;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
相關文章
相關標籤/搜索