mysql-5.7.10-linux-glibc2.5-i686.tar.gz是目前最新版,二進制發佈包,適合各類32爲版本的髮型版Linux,因爲只有一個包,解壓後配配就行,很方便,比較符合個人風格。mysql
環境:centos6.6 x86linux
一、下載 http://dev.mysql.com/downloads/mysql/sql
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-i686.tar.gz數據庫
迅雷下載後ftp傳到Linux下面/usr/local/soft/centos
二、解壓縮到/usr/local/下面,mysql的主目錄命名爲mysql緩存
[root@localhost local]# cd /usr/local/soft/ [root@localhost soft]# tar zvxf mysql-5.7.10-linux-glibc2.5-i686.tar.gz -C /usr/local [root@localhost soft]# cd .. [root@localhost local]# mv mysql-5.7.10-linux-glibc2.5-i686/ mysql
三、在mysql下面建立data數據庫文件目錄socket
[root@localhost local]# mkdir mysql/data
四、建立mysql的用戶組和用戶,並對mysql目錄設置用戶組和用戶ide
[root@localhost local]# groupadd mysql [root@localhost local]# useradd mysql -g mysql [root@localhost local]# cd mysql [root@localhost mysql]# pwd /usr/local/mysql [root@localhost mysql]# chown -R mysql . [root@localhost mysql]# chgrp -R mysql .
5.配置my.cnf文件ui
[mysqld]
#忽略密碼進入,這裏只有Linux系統有用
skip-grant-tables
basedir=/usr/local/mysql/mysql-5.7.19
datadir=/usr/local/mysql/mysql-5.7.19/data
socket=/var/lib/mysql/mysql.sock
user=mysql
port=3306
# 服務端使用的字符集默認爲8比特編碼的latin1字符集
character-set-server=utf8
#是指不區分大小寫 0-區分 1-不區分
lower_case_table_names=1
max_connections=1000
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
~
注意⚠️:在window系統忽略密碼不能寫在配置文件中 須要在cmd中執行 mysqld --console --skip-grant-tablesthis
cd /usr/local/mysql/mysql-5.7.19
./bin/mysqld --user=mysql --basedir=/usr/local/mysql/mysql-5.7.19 --datadir=/usr/local/mysql/mysql-5.7.19/data --initialize
./bin/mysqld
8.鏈接進入數據庫
./bin/mysql -uroot -p -S/var/lib/mysql/mysql.sock
9.鏈接數據庫完成,修改root用戶密碼
mysql>use mysql;
-- 查看user表結構,找到密碼字段 authentication_string
mysql>desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.01 sec)
mysql>update user set authentication_string=password('root') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
-- 刷新緩存,當即生效
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
-- 建立用戶,容許外網訪問
mysql>create user 'test'@'%' identified by '123456';
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
-- 給用戶賦予權限
mysql>grant all privileges on *.* to joe@localhost identified by '1';
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)