`
beike
  • 浏览: 361710 次
社区版块
存档分类
最新评论

CENTOS install mysql

阅读更多

当前的数据库种类比较多,有MS-SQL,Oracle,MYSQL,POSTGRESQL等,而MYSQL在LAMP架构中的份量是举足轻重的,下面就来介绍下Centos5下MySQL的安装和基本配置。

使用yum安装MySQL(在LAMP架构中,开始安装mysql之前应该先安装apache和php)
[root@centos5 /]# yum -y install mysql-server
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* base: centos.candishosting.com.cn
* updates: mirror.khlug.org
* addons: centos.candishosting.com.cn
* extras: centos.candishosting.com.cn
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.45-7.el5 set to be updated
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Processing Dependency: mysql = 5.0.45-7.el5 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
--> Running transaction check
---> Package perl-DBD-MySQL.i386 0:3.0007-1.fc6 set to be updated
---> Package mysql.i386 0:5.0.45-7.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
mysql-server            i386       5.0.45-7.el5     base              9.7 M
Installing for dependencies:
mysql                   i386       5.0.45-7.el5     base              4.1 M
perl-DBD-MySQL          i386       3.0007-1.fc6     base              147 k

Transaction Summary
=============================================================================
Install      3 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 14 M
Downloading Packages:
(1/3): mysql-5.0.45-7.el5 100% |=========================| 4.1 MB    02:57
(2/3): mysql-server-5.0.4 100% |=========================| 9.7 MB    07:19
(3/3): perl-DBD-MySQL-3.0 100% |=========================| 147 kB    00:07
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: mysql                        ######################### [1/3]
Installing: perl-DBD-MySQL               ######################### [2/3]
Installing: mysql-server                 ######################### [3/3]

Installed: mysql-server.i386 0:5.0.45-7.el5
Dependency Installed: mysql.i386 0:5.0.45-7.el5 perl-DBD-MySQL.i386 0:3.0007-1.fc6
Complete!

安装PHP访问MySQL数据库的工具“php-mysql”

[root@centos5 ~]# yum -y install php-mysql
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* base: centos.candishosting.com.cn
* updates: mirror.khlug.org
* addons: centos.candishosting.com.cn
* extras: centos.candishosting.com.cn
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Processing Dependency: php-pdo for package: php-mysql
--> Running transaction check
---> Package php-pdo.i386 0:5.1.6-20.el5_2.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php-mysql               i386       5.1.6-20.el5_2.1 updates            84 k
Installing for dependencies:
php-pdo                 i386       5.1.6-20.el5_2.1 updates            62 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 146 k
Downloading Packages:
(1/2): php-pdo-5.1.6-20.e 100% |=========================| 62 kB    00:20
(2/2): php-mysql-5.1.6-20 100% |=========================| 84 kB    00:11
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-pdo                      ######################### [1/2]
Installing: php-mysql                    ######################### [2/2]

Installed: php-mysql.i386 0:5.1.6-20.el5_2.1
Dependency Installed: php-pdo.i386 0:5.1.6-20.el5_2.1
Complete!

[root@centos5 ~]# vi /etc/my.cnf (编辑mysql配置文件)

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8 (添加这一行,让MySQL的默认编码为UTF-8)

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set = utf8 (添加这一行,设置mysql在安全模式启动后的默认编码为UTF-8)

[root@centos5 ~]# chkconfig mysqld on (设置mysql在开机后自动启动)
[root@centos5 ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off


[root@centos5 ~]# /etc/rc.d/init.d/mysqld start       (启动mysql服务)

Initializing MySQL database: 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:
/usr/bin/mysqladmin -u root password 'new-password'  

(在这里系统提示可以使用mysqladmin为root,localhost和root,centos5设置密码,centos5是我的主机名,可使用这个命令的时候系统却报错了!)
/usr/bin/mysqladmin -u root -h centos5 password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/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 /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [ OK ]
Starting MySQL:                                            [ OK ]


[root@centos5 /]# netstat -ntpl |grep mysqld
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LIST                                             EN      8168/mysqld

[root@centos5 /]# mysql -u root -p (正如前面提到的报错,在这里是因为root这个mysql用户已经有非空的密码存在了。)
Enter password:
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)

(在这里我在Internet上搜索到了一个解决的办法)


[root@centos5 /]# /etc/rc.d/init.d/mysqld stop (先停止mysql服务)
Stopping MySQL:                                            [ OK ]


[root@centos5 /]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&(重新启动mysql服务的时候加上这些参数,这些参数具体代表了什么,我也不明白,大概是设置启动服务的 时候跳过验证密码的表和网络吧!)
[1] 8850
Starting mysqld daemon with databases from /var/lib/mysql

[root@centos5 /]# /etc/rc.d/init.d/mysqld status
mysqld (pid 8902) is running...
[root@centos5 /]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>   (果然这次不用输入密码就可以进来了,也没有什么报错信息)


mysql> select user,host,password from mysql.user; (查看系用户表,果然localhost,root真的有密码,其他的两个都没有,如果用另外两个root用户登陆应该就不会出现之前的问题了)
+------+-----------+------------------+
| user | host      | password         |
+------+-----------+------------------+
| root | localhost | 7a3310dc39c1d3df |
| root | centos5   |                  |
| root | 127.0.0.1 |                  |
+------+-----------+------------------+
3 rows in set (0.01 sec)

 

mysql> UPDATE user SET Password=PASSWORD('123') where USER='root'; (接下来当然要修改下密码啦,这里就简单的设置成123)
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> show databases; (查看下当前的数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)

[root@centos5 /]# /etc/rc.d/init.d/mysqld stop (停止mysql服务)
STOPPING server from pid file /var/run/mysqld/mysqld.pid
090201 09:23:00 mysqld ended

Stopping MySQL:                                            [ OK ]
[1]+ Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking

[root@centos5 /]# /etc/rc.d/init.d/mysqld start (以正常的方式启动服务)
Starting MySQL:                                            [ OK ]

[root@centos5 /]# mysql -u root -p (输入密码123登陆)
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host from mysql.user; (查看用户,并删除另外的两个root用户)
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | centos5   |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)

mysql> delete from mysql.user where user='root' and host='127.0.0.1';
Query OK, 0 rows affected (0.01 sec)

mysql> delete from mysql.user where user='root' and host='centos5';
Query OK, 1 row affected (0.01 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
mysql> exit
Bye

重新启动一次HTTP服务,让php-mysql反映到HTTP服务中
[root@centos5 /]# /etc/rc.d/init.d/httpd restart  
Stopping httpd:                                            [ OK ]
Starting httpd:                                            [ OK ]

 

 

 

 

 

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;

grant all on depot_development.* to 'david'@'localhost' identified by 'lovelove';

分享到:
评论

相关推荐

    CentOS下mysql成功安装

    初始化数据库需要使用mysql_install_db命令来创建数据库文件和表结构。 注册为服务 将MySQL注册为系统服务,需要将mysql.server文件复制到/etc/rc.d/init.d目录下,然后使用chkconfig命令来添加MySQL服务。 启动...

    CentOS 7 安装 MySQL

    CentOS 7 安装 MySQL

    centos7上面的mysql5.7自动安装脚步mysql7install.sh

    脚步可以带版本参数执行./mysql7install.sh 5.7.29,如不带参赛默认安装5.7.30。本脚步具有一定自动调优功能,可以自动跟进机器资源完整部分参数调优,可供中型企业使用。这不能删除,也不能替换上传内容有点蛋疼呀...

    CentOS安装MySQL 5.5

    ### CentOS安装MySQL 5.5知识点详解 #### 1. 概述 本文档旨在指导如何在CentOS系统上从源代码编译、安装并配置MySQL 5.5数据库管理系统。该过程涉及到软件环境的准备、编译工具的安装、MySQL源代码的编译与配置等...

    centos 7 MySQL8 离线一键自动安装脚本

    - 安装MySQL8:使用`yum localinstall`命令安装RPM包,例如:`yum localinstall /opt/software/mysql-community-server*.rpm /opt/software/mysql-community-client*.rpm` - 初始化数据库:安装完成后,运行`...

    CentOS7中将Mysql添加为系统服务 - shangyingbin - 博客园.pdf

    这篇博客文章“CentOS7中将Mysql添加为系统服务”介绍了如何手动将自安装的MySQL服务添加到`systemd`中,以便进行自动化管理和维护。 首先,如果你是通过源码包自行安装的MySQL,那么默认情况下,MySQL不会自动添加...

    centos7搭建mysql集群

    ### CentOS 7 搭建 MySQL 集群详解 #### 一、概述 随着业务规模的扩大,单一数据库服务器往往难以满足高并发、大数据量的需求。为了提高系统的可用性和性能,采用 MySQL 集群成为一种常见的解决方案。本文将详细...

    linux(centos) 下C++连接mysql数据库

    在Linux(CentOS)系统中,使用C++连接MySQL数据库是一项常见的任务,特别是在开发服务器端应用程序时。这里我们将深入探讨如何实现这一目标,以及在这个过程中可能遇到的关键知识点。 首先,你需要确保你的系统...

    CentOS6.5一键安装Mysql5.6

    在Linux系统中,CentOS 6.5是一个广泛使用的版本,而MySQL 5.6则是一个流行的开源数据库管理系统。本文将详细介绍如何在CentOS 6.5上进行MySQL 5.6的一键安装过程,包括必要的环境准备、安装步骤、配置优化以及安全...

    centos下 MySQL 5.5.13 CMake 安装笔记

    在CentOS操作系统中,安装MySQL 5.5.13版本时,由于该版本需要使用CMake构建系统进行编译安装,这个过程相对复杂,但是一旦设置正确,可以确保MySQL服务器按照预期配置运行。以下是详细的安装步骤: 首先,确保你的...

    centos7 安装mysql和mysqlclient遇到的坑总结

    在CentOS7上安装MySQL和mysqlclient可能会遇到一些挑战,本文将总结这些常见的问题和解决方案。首先,我们需要为系统添加MySQL的Yum源以便能够安装MySQL的社区版本。可以通过访问MySQL官方网站的DOWNLOADS部分,找到...

    CentOS7安装mysql5.7.19&mysql5;.7.19主从配置(CentOS7)

    sudo yum install mysql-community-server ``` 4. **启动MySQL服务**:安装完成后,启动MySQL服务并设置开机启动: ``` sudo systemctl start mysqld sudo systemctl enable mysqld ``` 5. **设置root用户密码...

    centos安装mysql5.6.docx

    `yum install mysql-community-server -y` 启动 MySQL 并设置开机启动 安装 MySQL 5.6 后,我们需要启动 MySQL 并设置开机启动。可以使用以下命令启动 MySQL: `service mysqld start` 然后,我们可以使用以下...

    CentOS 7 MySQL 8.0的Shell安装.13 的脚本_MySql_CentOS_Install.zip

    CentOS 7 MySQL 8.0的Shell安装.13 的脚本_MySql_CentOS_Install

    centos7安装mysql文档及安装包

    在Linux系统中,CentOS 7是最常用的发行版之一,而MySQL是世界上最流行的开源关系型数据库管理系统。本文将详细介绍如何在CentOS 7上安装MySQL 5.7,基于提供的安装包进行操作。 首先,我们需要了解MySQL的组件结构...

    centos系统安装mysql5.7

    CentOS 系统安装 MySQL 5.7 在本文中,我们将指导您如何在 CentOS 6.8 系统中安装 MySQL 5.7。MySQL 是一个流行的关系数据库管理系统,广泛应用于各种 web 应用程序中。 检测系统是否自带安装 MySQL 在安装 MySQL...

    centos安装mysql主从步骤

    根据提供的文件信息,这里将详细解释如何在 CentOS 下安装 MySQL 主从配置的步骤。以下是具体的安装过程: ### 1. 确认 CentOS 版本 确保系统版本为 CentOS 6.3,可以通过命令行输入 `cat /etc/centos-release` 来...

    centos7安装配置mysql5.7教程全

    在Linux系统中,CentOS 7是广泛使用的服务器操作系统,而MySQL 5.7则是一款高性能、开源的关系型数据库管理系统。本教程将详细介绍如何在CentOS 7上完整地安装和配置MySQL 5.7。 一、安装MySQL 5.7 1. 更新系统:...

Global site tag (gtag.js) - Google Analytics