安装篇:
http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html
用yum方式安装
查看系统消息
[root@cqs ~]# uname -a
Linux cqs 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
首先检查是否已经安装过mysql
[root@cqs ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
有的话就卸载掉以前安装的mysql:
[root@localhost src]# rpm -e --nodeps xxx(xxx是搜索结果)
首先我们可以输入 yum list | grep mysql 命令来查看yum上提供的mysql数据库可下载的版本:
[root@cqs ~]# yum list | grep mysql
我们可以通过输入 yum install -y mysql-server mysql mysql-devel命令将mysql mysql-server mysql-devel都安装好
(注意:安装mysql时我们并不是安装了mysql客户端就相当于安装好了mysql数据库了,我们还需要安装mysql-server服务端才行)
[root@cqs ~]# yum install mysql-server mysql mysql-deve
已加载插件:fastestmirror
设置安装进程
总下载量:12 M
Installed size: 33 M
确定吗?[y/N]:y
完毕!
[root@cqs ~]#
可以通过如下命令,查看刚安装好的mysql-server的版本
[root@cqs ~]# rpm -qi mysql-server
Name : mysql-server Relocations: (not relocatable)
Version : 5.1.73 Vendor: CentOS
Release : 7.el6 Build Date: 2016年05月11日 星期三14时31分38秒
Install Date: 2016年12月01日 星期四14时05分51秒 Build Host: worker1.bsys.centos.org
Group : Applications/Databases Source RPM: mysql-5.1.73-7.el6.src.rpm
Size : 25883075 License: GPLv2 with exceptions
Signature : RSA/SHA1, 2016年05月12日 星期四18时49分52秒, 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.
我们在安装完mysql数据库以后,会发现会多出一个mysqld的服务,这个就是咱们的数据库服务,我们通过输入service mysqld start 命令就可以启动我们的mysql服务。
注意:如果我们是第一次启动mysql服务,mysql服务器首先会进行初始化的配置,如:
[root@cqs ~]# service mysqld start
初始化 MySQL 数据库:WARNING: The host 'cqs' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
正在启动 mysqld: [确定]
第一次启动mysql服务器以后会提示非常多的信息,目的就是对mysql数据库进行初始化操作,当我们再次重新启动mysql服务时,就不会提示这么多信息了,如:
[root@cqs ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
在使用mysql数据库时,都得首先启动mysqld服务,我们可以 通过chkconfig --list | grep mysqld 命令来查看mysql服务是不是开机自动启动,如:
[root@cqs ~]# chkconfig --list | grep mysqld
mysqld 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
发现此时的mysqld服务并没有开机自动启动,我们当然可以通过chkconfig mysqld on 命令来将其设置成开机启动,这样就不用每次都去手动启动了。
[root@cqs ~]# chkconfig mysqld on
再次查看
[root@cqs ~]# chkconfig --list | grep mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
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 cqs password 'new-password'
我们可以通过 该命令来给我们的root账号设置密码(注意:这个root账号是mysql的root账号,非Linux的root账号)
[root@cqs ~]# mysqladmin -u root password 'root'
[root@cqs ~]#
此时我们就可以通过 mysql -u root -p 命令来登录我们的mysql数据库了
[root@cqs ~]# 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
创建数据库cqs,
mysql> create database cqs;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cqs |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
接下来,简单介绍一些Mysql的主要配置文件
1./etc/my.cnf 这是mysql的主配置文件
[root@cqs ~]# cd /etc/
[root@cqs etc]# cat 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
2./var/lib/mysql mysql数据库的数据库文件存放位置
[root@cqs etc]# cd /var/lib/mysql
[root@cqs mysql]# ll
总用量 20492
drwx------. 2 mysql mysql 4096 12月 1 04:57 cqs
-rw-rw----. 1 mysql mysql 10485760 12月 1 05:12 ibdata1
-rw-rw----. 1 mysql mysql 5242880 12月 1 05:13 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 12月 1 02:38 ib_logfile1
drwx------. 2 mysql mysql 4096 12月 1 02:38 mysql
srwxrwxrwx. 1 mysql mysql 0 12月 1 05:13 mysql.sock
drwx------. 2 mysql mysql 4096 12月 1 02:38 test
3./var/log mysql数据库的日志输出存放位置
[root@cqs log]# cd /var/log/
[root@cqs log]# cat mysqld.log
其中mysqld.log 这个文件就是我们存放我们跟mysql数据库进行操作而产生的一些日志信息,通过查看该日志文件,我们可以从中获得很多信息。
我们的mysql数据库是可以通过网络访问的,并不是一个单机版数据库,其中使用的协议是tcp/ip 协议,我们都知道mysql数据库绑定的端口号是3306 ,所以我们可以通过netstat -anp 命令来查看一下,Linux系统是否在监听3306 这个端口号:
结果如上所示,Linux系统监听的3306端口号就是我们的mysql数据库!!!!