关于在Centos系统下安装MYSQL数据库,网络上资料有很多,在此主要感谢该文章的博主:http://www.cnblogs.com/zhoulf/archive/2013/01/25/zhoulf.html,因为相对来说,该篇文章具有很强的操作性。此文将在汇集众多资料的基础上,记录本人安装MYSQL的全过程。

一、配置环境与软件版本:

1、Centos版本:6.3版32位系统;

2、CMake版本:cmake-2.8.4.tar.gz;

3、Mysql版本:mysql-5.5.11.tar.gz;

二、安装过程如下:

该安装过程采用CMake编译的方式安装Mysql,所以需要安装CMake工具,再安装Mysql数据库,在安装这两个软件之前,需要安装gcc与ncurses-devel。

1、安装gcc编译工具,执行如下命令:

[root@localhost soft]# yum install gcc-c++

如果提示安装:Complete! 表示安装成功。

2、安装ncurses-devel编译工具,执行如下命令:

[root@localhost soft]# yum install ncurses-devel

如果提示安装:Complete! 表示安装成功。

3、安装CMake工具,执行软件解压命令和剪切到/usr/local目录下:

[root@localhost soft]# tar -zxvf cmake-2.8.4.tar.gz

[root@localhost soft]# mv cmake-2.8.4 /usr/local/cmake

进入到/usr/local/cmake目录下进行安装:

[root@localhost cmake]# ./configure

[root@localhost cmake]# make

[root@localhost cmake]# make install

将cmake永久加入系统环境变量:

[root@localhost cmake]# vi /etc/profile

在/etc/profile文件中添加与设置相应的环境变量:

export CMAKE_HOME=/usr/local/cmake

export PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin:$CMAKE_HOME/bin

注:红色部分的分号不要丢掉。

使/etc/profile文件立即生效:

[root@localhost cmake]# . /etc/profile

注:.与/etc/profile之间有空格。

查看设置的环境变量是否已生效:

[root@localhost cmake]# echo $PATH

显示结果:

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.6.0_30/bin:/usr/local/ant/bin:/root/bin:/usr/java/jdk1.6.0_30/bin

:/usr/local/ant/bin:/usr/local/cmake/bin

红色部分显示我们设置的环境变量已经生效。

4、安装Mysql数据库,执行软件解压命令和剪切到/usr/local目录下:

[root@localhost soft]# tar -zxvf mysql-5.5.11.tar.gz

[root@localhost soft]# mv mysql-5.5.11 /usr/local/mysql-5.5.11

创建mysql的安装目录及数据库存放目录:

[root@localhost soft]# mkdir -p /usr/local/mysql

[root@localhost soft]# mkdir -p /usr/local/mysql/data

创建mysql用户及用户组:

[root@localhost soft]# groupadd mysql

[root@localhost soft]# useradd -r -g mysql mysql

进入mysql-5.5.11主目录,编译安装mysql:

[root@localhost mysql-5.5.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

> -DDEFAULT_CHARSET=utf8 \

> -DDEFAULT_COLLATION=utf8_general_ci \

> -DWITH_MYISAM_STORAGE_ENGINE=1 \

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \

> -DWITH_MEMORY_STORAGE_ENGINE=1 \

> -DWITH_READLINE=1 \

> -DENABLED_LOCAL_INFILE=1 \

> -DMYSQL_DATADIR=/usr/local/mysql/data \

> -DMYSQL_USER=mysql \

> -DMYSQL_TCP_PORT=3306

  注:“>” 标识符是在行尾键入“\”符号时自动产生的。

[root@localhost mysql-5.5.11]# make

[root@localhost mysql-5.5.11]# make install

进入Mysql数据库的安装主目录/usr/local/mysql,设置相关的目录权限:

[root@localhost mysql]# chown -R root:mysql .

[root@localhost mysql]# chown -R mysql:mysql data

  注:把mysql数据库主目录中所有文件的所有者设为root,所属组为mysql。

将mysql的启动服务添加到系统服务中:

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf'? y

创建系统数据库的表:

[root@localhost mysql]# scripts/mysql_install_db --user=mysql

执行结果:

  1. Installing MySQL system tables...
  2. OK
  3. Filling help tables...
  4. OK
  5. To start mysqld at boot time you have to copy
  6. support-files/mysql.server to the right place for your system
  7. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  8. To do so, start the server, then issue the following commands:
  9. ./bin/mysqladmin -u root password 'new-password'
  10. ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
  11. Alternatively you can run:
  12. ./bin/mysql_secure_installation
  13. which will also give you the option of removing the test
  14. databases and anonymous user created by default.  This is
  15. strongly recommended for production servers.
  16. See the manual for more instructions.
  17. You can start the MySQL daemon with:
  18. cd . ; ./bin/mysqld_safe &
  19. You can test the MySQL daemon with mysql-test-run.pl
  20. cd ./mysql-test ; perl mysql-test-run.pl
  21. Please report any problems with the ./bin/mysqlbug script!
Installing MySQL system tables...
OK
Filling help tables...
OK To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run:
./bin/mysql_secure_installation which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl Please report any problems with the ./bin/mysqlbug script!

设置MYSQL的环境变量并做生效处理:

[root@localhost mysql]# vi /root/.bash_profile

在修改PATH=$PATH:$HOME/bin为:PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

最终如图:

[root@localhost mysql]# source /root/.bash_profile

  注:红色部分是文件生效处理,很重要。

手动启动Mysql数据库:

[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & mysqladmin -u root -p shutdown

  注:启动MySQL,提示输入密码时,不要输入密码,直接回车即可

                提示:

  1. mysqladmin: connect to server at 'localhost' failed
  2. error: 'Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock' (2)'
  3. Check that mysqld is running and that the socket: '/usr/local/mysql/mysql.sock' exists!
  4. [root@localhost mysql]# 140223 21:59:54 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
  5. [1]+  Done                    ./bin/mysqld_safe --user=mysql
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/usr/local/mysql/mysql.sock' exists!
[root@localhost mysql]# 140223 21:59:54 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended [1]+ Done ./bin/mysqld_safe --user=mysql

将Mysql的启动服务添加到系统服务中:

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

启动Mysql服务:

[root@localhost mysql]# service mysql start

最终结果:

  1. Starting MySQL... <span style="color: rgb(255, 0, 0);">ERROR</span>! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

  注:这里是权限问题,先改变权限

[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql

再次启动Mysql服务:

[root@localhost mysql]# /etc/init.d/mysql start

  1. Starting MySQL... SUCCESS!
Starting MySQL... SUCCESS!

修改MySQL的root用户的密码以及打开远程连接:

[root@localhost mysql]# mysql -u root mysql

进入MySQL数据库管理系统:

  1. Welcome to the MySQL monitor.  Commands end with ; or \g.
  2. Your MySQL connection id is 1
  3. Server version: 5.5.11-log Source distribution
  4. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  5. Oracle is a registered trademark of Oracle Corporation and/or its
  6. affiliates. Other names may be trademarks of their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9. mysql>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.11-log Source distribution Copyright (c) 2000, 2010, 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命令行执行如下命令:

mysql> use mysql;

Database changed

mysql> desc user;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";

  1. Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)

mysql> update user set Password = password('admin') where User='root';

  1. Query OK, 5 rows affected (0.01 sec)
  2. Rows matched: 5  Changed: 5  Warnings: 0
Query OK, 5 rows affected (0.01 sec)
Rows matched: 5 Changed: 5 Warnings: 0

mysql> select Host,User,Password from user where User='root';

mysql> flush privileges;

  1. Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)

mysql> exit

  1. Bye
Bye

重新登录:

[root@localhost mysql]# mysql -u root -p

从图中可以看到,成功登录,至此Mysql数据库的安装与权限配置完毕。

三、验证数据库的基本功能:

1、查看数据库表:

mysql> show tables;

结果如图:

结果正常。

四、问题:

本人在配置的过程中,一开始先改变了系统的主机名,发现在执行登陆的时候登陆不了,报“链接不上 localhost”,但是在取消主机名之后,安装过程顺利,如果有大牛知道这个问题,望不吝赐教。

http://blog.csdn.net/limingzhong198/article/details/19823629

CentOS下MYSQL数据库的安装的更多相关文章

  1. CentOS 下Mysql数据库的安装与配置

    一.mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常 的方便,在Linux上如果要安装数据库, ...

  2. Centos下MongoDB数据库的安装以及配置开机自启动(三)

    最近写了一个用node来操作MongoDB完成增.删.改.查.排序.分页功能的示例,并且已经放在了服务器上地址:http://39.105.32.180:3333. 在服务器上完全可以用yum来安装管 ...

  3. [转] Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置

    from:  http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得 ...

  4. Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置

    原文:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建好j ...

  5. Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置(转)

    原文地址:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建 ...

  6. Linux学习之CentOS(一)--CentOS6.6下Mysql数据库的安装与配置

    在这里我是通过yum来进行mysql数据库的安装的,通过这种方式进行安装,可以将跟mysql相关的一些服务.jar包都给我们安装好,所以省去了很多不必要的麻烦!!! [root@larry ~]# c ...

  7. Linux学习之CentOS--CentOS6.4下Mysql数据库的安装与配置【转】

      如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--C ...

  8. Linux学习之CentOS6下Mysql数据库的安装与配置

    转自:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建好j ...

  9. CentOS6.4/6.7下Mysql数据库的安装与配置(转载)

    通过RPM方式 给centos  安装mysql  最好有光盘,呵呵,网络也可以下载rpm安装包,不过文件较大. 1 挂载光盘 mount /dev/cdrom /mnt/cdrom/mount: b ...

随机推荐

  1. yum工具入门

    一yum介绍 注意学完了yum之后,rpm的使用频率就少了.有些功能yum用起来不如rpm更方便. CentOS: yum, dnfYUM: Yellowdog Update Modifier,rpm ...

  2. JindoFS解析 - 云上大数据高性能数据湖存储方案

    JindoFS背景 计算存储分离是云计算的一种发展趋势,传统的计算存储相互融合的的架构存在一定的问题, 比如在集群扩容的时候存在计算能力和存储能力相互不匹配的问题,用户在某些情况下只需要扩容计算能力或 ...

  3. DMA实验总结

    一.RCC设置 没什么好写的之前USART的基本一样 /************************************************************************ ...

  4. nucleus plus学习总结(后续)

    前言:     刚刚抽筋点了保存发布,结果要审核,那就分开写个续好了. 内容: signal     信号是异步通知task的一种机制,HISR是不可以接收信号的,但是可以发送信号.     TCB中 ...

  5. c#获取MAC地址和IP地址

    一获取mac地址 1.先添加system.management的dll组件2.添加引用 public string GetMACAddress(){string MoAddress = "& ...

  6. paper 139:qt超强绘图控件qwt - 安装及配置

    qwt是一个基于LGPL版权协议的开源项目, 可生成各种统计图.它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式 ...

  7. python 的按位与、或、异或 运算

    符号 描述 运算规则                        by MoreWindows & 与 两个位都为1时,结果才为1     (统计奇数) | 或 两个位都为0时,结果才为0  ...

  8. (6)C++ 函数

    一.基本知识  1.为什么需要原型? 原型描述了函数到编译器的接口,将函数返回值类型以及参数类型.参数数量告诉编译器. 首先原型告诉编译器方法存在某些参数,如果没有原型会让编译器捕获这种错误. 其次函 ...

  9. 一个普通函数的冷僻属性(length、caller、arguments、name、[[Scopes]]和[[FunctionLocation]])

    https://blog.csdn.net/qq_17175013/article/details/81915059

  10. oninput 事件 比较angular张的 ng-model指令 和 Vue中的 v-model指令

    oninput 事件在用户输入时触发. 该事件在 <input> 或 <textarea> 元素的值发生改变时触发. 提示: 该事件类似于 onchange 事件.不同之处在于 ...