centos7 mysql資料庫安裝和配置

2021-08-03 09:49:26 字數 2498 閱讀 1840

yum update公升級以後的系統版本為

[root@yl-web yl]# cat /etc/redhat-release 

centos linux release 7.1.1503 (core)

# wget 

# rpm -ivh mysql57-community-release-el7-11.noarch.rpm

# yum install mysql-community-server

安裝成功後重啟mysql服務。

# service mysqld restart
初次安裝mysql,root賬戶沒有密碼。

為了加強安全性,mysql5.7為root使用者隨機生成了乙個密碼,在error log中,關於error log的位置,如果安裝的是rpm包,則預設是/var/log/mysqld.log。

可通過# grep "password" /var/log/mysqld.log 命令獲取mysql的臨時密碼

2016-01-19t05:16:36.218234z 1 [note] a temporary password is generated for root@localhost: waq,qr%be2(5
拿到臨時密碼後,通過臨時密碼登入mysql後,必須修改i

[root@yl-web yl]# mysql -u root -p

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 3

server version: 5.6.26 mysql community server (gpl)

oracle is a registered trademark of oracle corporation and/or its

affiliates. other names may be trademarks of their respective

owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql> show databases;

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

| database |

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

| information_schema |

| mysql |

| performance_schema |

| test |

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

4 rows in set (0.01 sec)

mysql>

設定密碼,密碼必須是字母大小寫,數字,字元組成:例如:_vv)vvrw9/im

mysql> set password for 'root'@'localhost' =password('password');
query ok, 0 rows affected (0.00 sec)

mysql>

不需要重啟資料庫即可生效。

把在所有資料庫的所有表的所有許可權賦值給位於所有ip位址的root使用者。

mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新使用者而不是root,則要先新建使用者

mysql>create user 'username'@'%' identified by 'password';
此時就可以進行遠端連線了。

2、配置字符集為utf8

修改mysql配置檔案

預設位置:/etc/my.cnf

進入etc資料夾》vim my.cnf

是我新增設定後的。

* 我的mysql沒有[client]這個字段,首先新增上,在[client]段增加下面**default-character-set=utf8(網上還有提到其他的設定語句,是以前的版本,現在不用了)

[client]

default-character-set=utf8

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

:wq! #儲存退出

#service mysqld restart #重啟mysql

centos7 mysql資料庫連不上,救急操作

方法 重置mysql密碼,無需輸入centos7系統密碼 第一步 修改配置檔案免密碼登入mysql,vim etc my.cnf 在 mysqld 最後加上如下語句 並保持退出檔案 skip grant tables 重啟mysql服務 systemctl restart mysqld.servic...

centos7 mysql資料庫安裝和配置

yum update公升級以後的系統版本為 root localhost cat etc redhat release centos linux release 7.5.1804 core 一般網上給出的資料都是 yum install mysql yum install mysql server ...

centos7 mysql資料庫安裝和配置

wget rpm ivh mysql community release el7 5.noarch.rpm yum install mysql community server 安裝成功後重啟mysql服務。service mysqld restart初次安裝mysql,root賬戶沒有密碼。設定密...