CentOs6安裝配置mysql

1.刪除原有mysql
rpm -qa | grep mysql //查看系統是否已經安裝了mysql
如果有
rpm -e mysql  // 普通刪除模式
rpm -e --nodeps mysql  // 強力刪除模式
2.使用yum進行mysql的安裝
首先我們輸入 yum list | grep mysql 命令查看yum上提供的mysql數據庫支持版本

[root@host /]# yum list | grep mysql
mysql-libs.i686                            5.1.73-8.el6_8                @base  
mysql-server.i686                          5.1.73-8.el6_8                @base  
apr-util-mysql.i686                        1.3.9-3.el6_0.1               base   
bacula-director-mysql.i686                 5.0.0-13.el6                  base   
bacula-storage-mysql.i686                  5.0.0-13.el6                  base   
dovecot-mysql.i686                         1:2.0.9-22.el6                base   
freeradius-mysql.i686                      2.2.6-7.el6_9                 base   
libdbi-dbd-mysql.i686                      0.8.3-5.1.el6                 base   
mod_auth_mysql.i686                        1:3.0.0-11.el6_0.1            base   
mysql.i686                                 5.1.73-8.el6_8                base   
mysql-bench.i686                           5.1.73-8.el6_8                base   
mysql-connector-java.noarch                1:5.1.17-6.el6                base   
mysql-connector-odbc.i686                  5.1.5r1144-7.el6              base   
mysql-devel.i686                           5.1.73-8.el6_8                base   
mysql-embedded.i686                        5.1.73-8.el6_8                base   
mysql-embedded-devel.i686                  5.1.73-8.el6_8                base   
mysql-test.i686                            5.1.73-8.el6_8                base   
pcp-pmda-mysql.i686                        3.10.9-9.el6                  base   
php-mysql.i686                             5.3.3-49.el6                  base   
qt-mysql.i686                              1:4.6.2-28.el6_5              base   
rsyslog-mysql.i686                         5.8.10-12.el6                 base   
rsyslog7-mysql.i686                        7.4.10-7.el6                  base   





輸入 yum install -y mysql-server mysql mysql-devel 將mysql mysql-server 和 mysql-devel都安裝好
(注意:安裝mysql時需要安裝了mysql客戶端和安裝mysql-server服務端兩個才行)
[root@host /]# yum install -y mysql-server mysql mysql-deve

查看mysql-server的版本
[root@host /]# rpm -qi mysql-server
Name        : mysql-server                 Relocations: (not relocatable)
Version     : 5.1.73                            Vendor: CentOS
Release     : 8.el6_8                       Build Date: Thu 26 Jan 2017 04:41:51 PM EST
Install Date: Sat 11 Aug 2018 10:51:31 PM EDT      Build Host: c1bm.rdu2.centos.org
Group       : Applications/Databases        Source RPM: mysql-5.1.73-8.el6_8.src.rpm
Size        : 25690035                         License: GPLv2 with exceptions
Signature   : RSA/SHA1, Thu 26 Jan 2017 05:35:23 PM EST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.mysql.com
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

3.mysql數據庫的初始化及相關配置
裝完mysql數據庫以後,會發現會多出一個mysqld的服務,這個就是咱們的數據庫服務,我們通過輸入 service mysqld start 命令就可以啓動我們的mysql服務。
[root@host /]# service mysqld start

重啓命令
[root@host /]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
我們在使用mysql數據庫時,都得首先啓動mysqld服務,我們可以 通過  chkconfig --list | grep mysqld 命令來查看mysql服務是不是開機自動啓動,如:
[root@host /]#  chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
現在顯示全部關閉,我們將其打開,進行開機自啓動
[root@host /]# chkconfig mysqld on
[root@host /]#  chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

mysql數據庫安裝完以後只會有一個root管理員賬號,但是此時的root賬號還並沒有爲其設置密碼,在第一次啓動mysql服務時,會進行數據庫的一些初始化工作,在輸出的一大串信息中,我們看到有這樣信息 :
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h host.localdomain password 'new-password'

/ 命令給root賬號設置密碼爲 root
/usr/bin/mysqladmin -u root password 'root'
通過 mysql -u root -p 命令來登錄我們的mysql數據庫
[root@host /]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> 
4.mysql數據庫的主要配置文件
======/etc/my.cnf=======
[root@host /]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# 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
[root@host /]# 
mysql 安裝目錄
======/var/lib/mysql
5.創建數據庫(設置賬號密碼)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> create database open;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| open               |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on open.* to openuser@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

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

[注意]
grant all privileges on 數據庫名稱.* to 數據庫用戶名@'授權範圍' identified by '數據庫用戶名密碼';
授權範圍:%代表授權全網,localhost代表授權本機
5.電腦遠程連接mysql
1.查看端口號
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)

2.使用Navicat 或其他工具連接數據庫

ip:96.41.189.83
port:3306
username:openuser
password:123456


連接成功!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章