[root@stonex ~]# yum -y install mysql-server安装结果:Installed: mysql-server.x86_64 0:5.1.73-3.el6_5 Dependency Installed: mysql.x86_64 0:5.1.73-3.el6_5 perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6第2步、设置开机启动[root@stonex ~]# chkconfig mysqld on第3步、启动MySql服务[root@stonex ~]# service mysqld start第4步、设置MySQL的root用户设置密码[root@stonex ~]# mysql -u rootWelcome to the MySQL monitor. Commands end with ; or g....... 省略了一些行mysql> select user,host,password from mysql.user;查询用户的密码,都为空,用下面的命令设置root的密码为rootmysql> set password for root@localhost=password(‘root‘);mysql> exit第5步、用新密码登陆[root@stonex ~]# mysql -u root -p第6步、基本命令show databases; //查看系统已存在的数据库use databasesname; //选择需要使用的数据库drop database databasename; //删除选定的数据库exit //退出数据库的连接create database test01; //建立名为test的数据库show tables; // 列出当前数据库下的表其他基本的增删改查使用标准SQL即可第7步、开放远程登录权限
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;FLUSH PRIVILEGES;
centos6下的mysql的安装
标签:
小编还为您整理了以下内容,可能对您也有帮助:
如何在CentOS6下实现Apache+PHP+MySQL的快速安装
LAMP是一个免费、开源的解决方案,代表了Linux、Apache、MySQL、PHP,主要用作建立可行的通用的web服务器。那么如何在CentOS6下实现安装Apache+php+Mysql的快速安装?其具体安装配置步骤可以如下进行:
1.准备工作
使用yum进行安装,为了提高速度,最好先是修改为中国CentOS镜像服务器。目前国内有三个镜像可以选择,分别是:中国科学技术大学、163和Sohu的镜像,建议教育网用户选择中科大,电信用户选择163
下面命令是备份CentOS-Base.repo文件,并修改使用163镜像作为yum源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.save
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
mv CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
2.更新系统内核
yum -y update
3.安装Apahce、Mysql、PHP
yum -y install httpd php mysql mysql-server
默认情况下,mysql数据目录位于/var/lib/mysql
4.安装相关组件:
yum install php-mysql php-gd php-imap php-ldap php-odbc
php-pear php-xml php-xmlrpc
5.安装MySQL管理工具phpMyAdmin
yum -y install phpMyAdmin
6.配置Apache随系统启动
chkconfig --levels 235 httpd on
/etc/init.d/httpd start
7.配置MySQL随系统启动
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
8.设置数据库root密码
/usr/bin/mysqladmin -u root password 'New+Password#www.yupengyan.com'
9.测试PHP是否安装成功
在 CentOS 中 Apache 的默认根目录是 /var/www/html,配置文件 /etc/httpd/conf/httpd.conf。其他配置存储在 /etc/httpd/conf.d/ 目录。
centos安装mysql数据库的方法
1、首先下载MySQL的安装文件,我这里安装的是MySQL5.1.7版本的,
2、安装MySQL数据库服务器
进入安装包所在文件夹,执行命令 rpm -ivh MySQL-server-5.1.7-0.i386.rpm 安装MySQL服务器。
如果报了与原先版本冲突的话,就执行rpm -qa|grep -i mysql命令,会显示已安装的Mysql版本,我的显示mysql-libs-5.1.61-4.el6.i686
这时如果有的话就强制删除:rpm -e --nodeps mysql-libs-5.1.61-4.el6.i686(因为有包依赖,所以要强制删除)
我的报错提示如下:
复制代码
代码如下:
MySQL-server-5.1.7-0.i386.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp1250.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp1251.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp1256.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp1257.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp850.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp852.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp866.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/dec8.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/geostd8.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/greek.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/hebrew.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/hp8.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/keybcs2.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/koi8r.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/koi8u.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/latin1.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/latin2.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/latin5.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/latin7.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/macce.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/macroman.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/swe7.xml from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/tch/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/english/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/estonian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/french/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/german/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/greek/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/hungarian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/italian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/japanese/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/korean/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/norwegian-ny/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/norwegian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/polish/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/portuguese/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/romanian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/russian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/serbian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/slovak/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/spanish/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/swedish/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/ukrainian/errmsg.sys from install of MySQL-server-5.1.7-0.i386.rpm conflicts with file from package mysql-libs-5.1.61-4.el6.i686
这时候再执行rpm -ivh MySQL-server-5.1.7-0.i386.rpm安装即可安装成功。
我这里安装成功了,但是mysql服务无法启动,总是启动失败,后来百度了一下,是因为selinux的原因,只要将selinux关闭就OK了。
关闭selinux:vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 然后重启
关闭selinux之后还是无法启动mysql服务,因为安装的mysql所有者是root,在安装mysql的时候会创建一个用户mysql,只要将/var/lib/mysql
的所有者改为mysql就OK了,执行命令chown -R mysql:mysql /var/lib/mysql
现在执行service mysql start终于可以启动mysql服务了。
3.安装MySQL客户端
执行命令rpm -ivh MySQL-client-5.1.7-0.i386.rpm进行安装。
4.安装成功
成功安装MySQL后将sql文件导入到数据库,步骤如下:
进入MYSQL Command Line Client
1、先创建数据库:create database test 注:test是创建数据库的名称
2、再切换到当前数据库:use test
3、再输入:/. /root/test.sql 或 souce /root/test.sql
按照以上步骤就可以将备份的sql脚本导入到linux中的数据库中去。
在CentOS 6.3中安装与配置Mysql-5.5.29的方法
一、安装mysql
安装方式分为:rpm和源码编译安装两种,本文采用mysql源码编译方式,编译器使用Cmake。软件需要mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz,请自行下载。
下载地址:
http://mysql.mirror.kangaroot.net/Downloads/
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
其中mysql使用最新的稳定版本,即最新试用版的上一个版本,且非rc或者alpha的版本,Cmake直接用的最新版。
1.上传mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz到/usr/local文件夹下。
2.CentOS安装g++和ncurses-devel
复制代码
代码如下:
[root@zck local]# yum install gcc-c++
[root@zck local]# yum install ncurses-devel
3.cmake的安装
复制代码
代码如下:
[root@zck]# tar -zxv -f cmake-2.8.10.2.tar.gz // 解压压缩包
[root@zck local]# cd cmake-2.8.10.2
[root@zck cmake-2.8.10.2]# ./configure
[root@zck cmake-2.8.10.2]# make
[root@zck cmake-2.8.10.2]# make install
4.将cmake永久加入系统环境变量
用vi在文件/etc/profile文件中增加变量,使其永久有效,
[root@zck local]# vi /etc/profile
在文件末尾追加以下两行代码:
复制代码
代码如下:
PATH=/usr/local/cmake-2.8.10.2/bin:$PATH
export PATH
执行以下代码使刚才的修改生效:
[root@zck local]# source /etc/profile
用 export 命令查看PATH值
[root@zck local]# echo $PATH
5.创建mysql的安装目录及数据库存放目录
复制代码
代码如下:
[root@zck]# mkdir -p /usr/local/mysql //安装mysql
[root@zck]# mkdir -p /usr/local/mysql/data //存放数据库
6.创建mysql用户及用户组
复制代码
代码如下:
[root@zck] groupadd mysql
[root@zck] useradd -r -g mysql mysql
7.编译安装mysql
复制代码
代码如下:
[root@zck local]# tar -zxv -f mysql-5.5.29.tar.gz //解压
[root@zck local]# cd mysql-5.5.29
[root@zck mysql-5.5.29]#
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@zck mysql-5.5.29]# make
[root@zck mysql-5.5.29]# make install
8.检验是否安装成功
复制代码
代码如下:
[root@zck mysql-5.5.29]# cd /usr/local/mysql/
[root@zck mysql]# ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
有bin等以上文件的话,则说明成功安装mysql。
二、配置mysql
9.设置mysql目录权限
复制代码
代码如下:
[root@zck mysql]# cd /usr/local/mysql //把当前目录中所有文件的所有者设为root,所属组为mysql
[root@zck mysql]# chown -R root:mysql .
[root@zck mysql]# chown -R mysql:mysql data
10.将mysql的启动服务添加到系统服务中
复制代码
代码如下:
[root@zck mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
11.创建系统数据库的表
复制代码
代码如下:
[root@zck mysql]# cd /usr/local/mysql
[root@zck mysql]# scripts/mysql_install_db --user=mysql
12.设置环境变量
复制代码
代码如下:
[root@zck ~]# vi /root/.bash_profile
在修改PATH=$PATH:$HOME/bin为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@zck ~]# source /root/.bash_profile //使刚才的修改生效
13.手动启动mysql
复制代码
代码如下:
[root@zck ~]# cd /usr/local/mysql
[root@zck mysql]# ./bin/mysqld_safe --user=mysql //启动MySQL,但不能停止
mysqladmin -u root -p shutdown //此时root还没密码,所以为空值,提示输入密码时,直接回车即可。
14.将mysql的启动服务添加到系统服务中
复制代码
代码如下:
[root@zck mysql]# cp support-files/mysql.server /etc/init.d/mysql
15.启动mysql
复制代码
代码如下:
[root@zck mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
启动失败:
我这里是权限问题,先改变权限
[root@zck mysql]# chown -R mysql:mysql /usr/local/mysql
接着启动服务器
[root@zck mysql]# /etc/init.d/mysql start
16.修改MySQL的root用户的密码以及打开远程连接
复制代码
代码如下:
[root@zck mysql]# mysql -u root mysql
mysql use mysql;
mysql desc user;
mysql GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力
mysql update user set Password = password('123456') where User='root'; //设置root用户密码
mysql select Host,User,Password from user where User='root';
mysql flush privileges;
mysql exit
17.重新登录
复制代码
代码如下:
[root@zck mysql]# mysql -u root -p
Enter password:123456
若还不能进行远程连接,关闭防火墙
复制代码
代码如下:
[root@zck]# /etc/rc.d/init.d/iptables stop