1.通過下面的命令查看環境中是否安裝了mysql數據庫,系統的只安裝了mysql類庫,沒有安裝mysql
[root@mysql001 opt]# rpm -qa | grep mysql
mysql-libs-5.1.73-7.el6.x86_64
2.mysql安裝軟件下載
國內的一些下載網絡比較的麻煩,大家都懂的,大家可以通過下面的地址去下載。
http://mirrors.sohu.com/mysql/
3.查看Linux的版本信息
[root@mysql001 opt]# cat /etc/redhat-release
CentOS release 6.8 (Final)
4.mysql用戶和組創建
[root@mysql001 opt]# groupadd mysql
[root@mysql001 opt]# useradd -g mysql mysql
[root@mysql001 opt]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@mysql001 opt]#
5.將下載的安裝包上傳到/opt目錄下面,解壓
[root@mysql001 opt]# tar zxvf ./mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
6.解壓的文件夾創建軟連接
[root@mysql001 opt]# ln -s /opt/mysql-5.6.34-linux-glibc2.5-x86_64 /opt/mysql
7.解壓的文件夾的所有者改爲mysql
[root@mysql001 opt]# chown -R mysql ./mysql
[root@mysql001 opt]# chown -R mysql ./mysql-5.6.34-linux-glibc2.5-x86_64
8.初始化mysql數據庫
[root@mysql001 mysql]# scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
9.拷貝mysql的啓動文件
cp support-files/mysql.server /etc/init.d/mysqld
修改文件中的內容
basedir=/opt/mysql
datadir=/opt/mysql/data
10.拷貝mysql配置文件
cp my.cnf /etc/my.cnf
修改文件中的內容
basedir = /opt/mysql
datadir = /opt/mysql/data
port = 3306
server_id = 1
11.啓動mysql服務
[root@mysql001 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
12.改變mysql的密碼
[root@mysql001 bin]# pwd
/opt/mysql/bin
[root@mysql001 bin]# ./mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.34 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
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> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | mysql001 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mysql001 | |
+------+-----------+----------+
6 rows in set (0.01 sec)
mysql> update mysql.user set password=password('gaojian123') where user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
13.設置mysql能夠進行遠程連接
[root@mysql001 bin]# pwd
/opt/mysql/bin
[root@mysql001 bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.34 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
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> 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
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| 127.0.0.1 |
| ::1 |
| localhost |
| mysql001 |
+-----------+
4 rows in set (0.00 sec)
mysql> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| % |
| 127.0.0.1 |
| ::1 |
| mysql001 |
+-----------+
4 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
※#修改host值(以通配符%的內容增加主機/IP地址,當然也可以直接增加某個特定IP地址,如果執行update語句時出現ERROR 1062 (23000):
Duplicate entry '%-root' for key 'PRIMARY' 錯誤,需要select host from user where user = 'root';
查看一下host是否已經有了%這個值,如果有了直接執行下面的flush privileges;即可)
14.爲了方便使用mysql命令,添加環境變量
MYSQL_HONE=/opt/mysql
PATH=$MYSQL_HONE/bin:$PATH
export PATH