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

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 7 安装 MySQL

    CentOS 7 安装 MySQL

    centos7 mysql8 (8.0.27) rpm静态安装包

    tar -zxvf mysql8.tar.gz解压后,文件夹里包含mysql8安装的依赖文件,perl rpm文件和mysql rpm文件,直接执行脚本mysql8.sh install安装或者mysql8.sh uninstall卸载,基本上是一键安装或者卸载了,只包含了安装,不...

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

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

    centos中mysql下载安装.docx

    在centos如何安装MySQL 1.Rpm -qa | grep mysql -------查看是否安装了mysql 2.Yum -y install mysql----卸载无关组件 新手博主上传,请见谅

    CentOS7安装MySQL教程

    CentOS7安装MySQL教程https://www.cnblogs.com/bigbrotherer/p/7241845.html wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm yum -y install mysql57-community-release-el7-10....

    更新centos的mysql安装源

    默认centos使用yum install安装的mysql版本很低,需要更新远程mysql仓库 适用于RedHat7/Centos7/Oracle Linux7

    Auto install Mysql on CentOS

    2,创建目录/data/mysql #mkdir -p /data/mysql 3,修改脚本内容,将“MYSQL='mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz'” 改成对应的镜像名 4,sudo ln -s /usr/lib64/libncurses.so.6.1 /usr/lib64/libncurses...

    centos7安装mysql

    在CentOS 7上安装MySQL可以按照以下步骤进行: 打开终端并以root用户身份登录服务器。 使用以下命令更新系统软件包: yum update 安装MySQL的软件存储库。执行以下命令导入MySQL存储库的RPM包: rpm -Uvh ...

    Centos7安装mysql5.7.doc

    CentOS7安装mysql yum方式 1.下载 wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 4.本地安装yum源 yum localinstall mysql57-community-release-el7-11.noarch.rpm 5.检测是否已经...

    redhat/centos版本>=7.x系统一键安装mysql数据库5.7.x并配置基线安全策略shell脚本

    2.使用root执行脚本,命令最好是source install-dbsql.sh,否则mysql命令无法在最后生效 3.请确保端口3306(可更改)没有被占用,安全要求默认端口3306不可启用 4.请尽量确保yum源可用 5.暂时不支持centos和redhat 版本...

    centOS安装mysql5.7详细教程

    本文为大家分享了centOS下安装mysql5.7详细步骤,供大家参考,具体内容如下 第一步: 第一句检测系统是否自带安装mysql,若有执行第二句删除系统自带的mysql及其依赖。...yum localinstall mysql-community-rele

    houko#StudingRecord#CentOS下安装Mysql1

    CentOS安装Mysql> 使用yum进行安装配置yum源yum -y install mysql-serverCentOS 7的yum源中貌似没有正常安装M

    rpminstall_mysql.sh

    3、./rpminstall_msyql.sh运行自动安装mysql57 4、数据库初始化: 为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化 mysqld --initialize --...

    centOS下mysql workbench安装配置教程

    yum install mysql mysql-server mysql-libs mysql-server 关于mysql各个包的功能是: “mysqlfor the client tools,mysql-serverfor the server and associated tools, andmysql-libsfor the libraries. The ...

    mysql8一键化安装脚本

    mysql8一键化安装脚本 1 可以自由安装在任何目录下(直接回车默认安装在/auto),而且所有的东西都在此目录下,不会出现在其他目录中 2 内置可以在存储过程中执行Linux命令插件 3 安装完成后,cd /auto/mysql/support-...

    CentOS7.7中安装MySQL5.7教程(超详细)

    在CentOS中,执行sudo yum install mysql命令,不会安装mysql数据库,而是会安装MariaDB。 关于MySQL和MariaDB的关系,请参考百度百科。 在CentOS里安装MySQL要复杂一些,具体过程如下。 从mysql官网下载mysql仓库,...

    centos7 mysql安装

    1.下载mysql官方rpm # 下载地址 https://dev.mysql.com/downloads/ # 选择 MySQL Yum Repository ...yum -y install mysql57-community-release-el7-10.noarch.rpm yum -y install mysql-community-server 3.启动Mysq

    CentOS安装mysql5.7 及简单配置教程详解

    安装 保证你的用户有权限 安装 没有 切换 root su root (su的意思:swich user) # rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm ...# yum install mysql-community-server

    centos6.4下mysql5.7.18安装配置方法图文教程

    centos6.4下安装mysql5.7.18的具体步骤,分享给大家。 1、首先检查是否已经安装过mysql,查找mysql相关软件rpm包 #rpm -qa | grep mysql 2、将所有与mysql相关的东西删除 #yum -y remove mysql-libs-5.1.66-2.el6_...

    CentOS 7.0编译安装cmake和mysql安装包

    ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库 ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接 cp ./support-files/...

Global site tag (gtag.js) - Google Analytics