下面就是小编给大家带来的linux中mySQL的安装和配置教程linux操作系统,本文共8篇,希望大家喜欢阅读!

篇1:linux中mySQL的安装和配置教程linux操作系统
在linux中安装程序与应用程序都不像windows那么方便可直接安装了,下面我来介绍linux中mySQL的安装和配置方法有需要的朋友可参考,
本文的Linux环境是 Red Hat 9.0,MySQL是4.0.16。
二、安装Mysql
1、下载MySQL的安装文件
安装MySQL需要下面两个文件:
MySQL-server-4.0.16-0.i386.rpm
MySQL-client-4.0.16-0.i386.rpm
下载地址为:www.mysql.com/downloads/mysql-4.0.html,打开此网页,下拉网页找到“Linux x86 RPM
downloads”项,找到“Server”和“Client programs”项
,下载需要的上述两个rpm文件。
2、安装MySQL
rpm文件是Red Hat公司开发的软件安装包,rpm可让Linux在安装软件包时免除许多复杂的手续。该命令在安装时
常用的参数是 –ivh ,其中i表示将安装指定的rmp软件包,V
表示安装时的详细信息,h表示在安装期间出现“#”符号来显示目前的安装过程。这个符号将持续到安装完成后才停
止。
1)安装服务器端
在有两个rmp文件的目录下运行如下命令:
[root@test1 local]# rpm -ivh MySQL-server-4.0.16-0.i386.rpm
显示如下信息。
warning: MySQL-server-4.0.16-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing… ########################################### [100%]
1:MySQL-server ########################################### [100%]
。。。。。。(省略显示)
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h test1 password ‘new-password’
。。。。。。(省略显示)
Starting mysqld daemon with databases from /var/lib/mysql
如出现如上信息,服务端安装完毕。测试是否成功可运行netstat看Mysql端口是否打开,如打开表示服务已经启
动,安装成功。Mysql默认的端口是3306。
[root@test1 local]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local AddressForeign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:*LISTEN
上面显示可以看出MySQL服务已经启动。
2)安装客户端
运行如下命令:
[root@test1 local]# rpm -ivh MySQL-client-4.0.16-0.i386.rpm
warning: MySQL-client-4.0.16-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing… ########################################### [100%]
1:MySQL-client ########################################### [100%]
显示安装完毕。
用下面的命令连接mysql,测试是否成功。
三、登录MySQL
登录MySQL的命令是mysql, mysql 的使用语法如下:
mysql [-u username] [-h host] [-p[password]] [dbname]
username 与 password 分别是 MySQL 的用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个
root用户不是Linux的系统用户。MySQL默认用户是root,由于
初始没有密码,第一次进时只需键入mysql即可。
[root@test1 local]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.16-standard
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
出现了“mysql>”提示符,恭喜你,安装成功!
增加了密码后的登录格式如下:
mysql -u root -p
Enter password: (输入密码)
其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。
注意:这个mysql文件在/usr/bin目录下,与后面讲的启动文件/etc/init.d/mysql不是一个文件。
四、MySQL的几个重要目录
MySQL安装完成后不象SQL Server默认安装在一个目录,它的数据库文件、配置文件和命令文件分别在不同的目
录,了解这些目录非常重要,尤其对于Linux的初学者,因为
Linux本身的目录结构就比较复杂,如果搞不清楚MySQL的安装目录那就无从谈起深入学习。
下面就介绍一下这几个目录。
1、数据库目录
/var/lib/mysql/
2、配置文件
/usr/share/mysql(mysql.server命令及配置文件)
3、相关命令
/usr/bin(mysqladmin mysqldump等命令)
4、启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)
五、修改登录密码
MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。
1、命令
usr/bin/mysqladmin -u root password ‘new-password’
格式:mysqladmin -u用户名 -p旧密码 password 新密码
2、例子
例1:给root加个密码123456,
键入以下命令 :
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
3、测试是否修改成功
1)不用密码登录
[root@test1 local]# mysql
ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: NO)
显示错误,说明密码已经修改。
2)用修改后的密码登录
[root@test1 local]# mysql -u root -p
Enter password: (输入修改后的密码123456)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.16-standard
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
成功!
这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。
六、启动与停止
1、启动
MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。
[root@test1 init.d]# /etc/init.d/mysql start
2、停止
/usr/bin/mysqladmin -u root -p shutdown
3、自动启动
1)察看mysql是否在自动启动列表中
[root@test1 local]# /sbin/chkconfig –list
2)把MySQL添加到你系统的启动服务组里面去
[root@test1 local]# /sbin/chkconfig – add mysql
3)把MySQL从启动服务组里面删除。
[root@test1 local]# /sbin/chkconfig – del mysql
七、更改MySQL目录
MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/data下需要进行下面几步:
1、home目录下建立data目录
cd /home
mkdir data
2、把MySQL服务进程停掉:
mysqladmin -u root -p shutdown
3、把/var/lib/mysql整个目录移到/home/data
mv /var/lib/mysql /home/data/
这样就把MySQL的数据文件移动到了/home/data/mysql下
4、找到my.cnf配置文件
如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名
为my.cnf)中。命令如下:
[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
5、编辑MySQL的配置文件/etc/my.cnf
为保证MySQL能够正常工作,需要指明mysql.sock文件的产生位置。 修改socket=/var/lib/mysql/mysql.sock一
行中等号右边的值为:/home/mysql/mysql.sock 。操作如下
:
vi my.cnf (用vi工具编辑my.cnf文件,找到下列数据修改之)
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock(原内容,为了更稳妥用“#”注释此行)
socket = /home/data/mysql/mysql.sock (加上此行)
6、修改MySQL启动脚本/etc/rc.d/init.d/mysql
最后,需要修改MySQL启动脚本/etc/rc.d/init.d/mysql,把其中datadir=/var/lib/mysql一行中,等号右边的
路径改成你现在的实际存放路径:home/data/mysql。
[root@test1 etc]# vi /etc/rc.d/init.d/mysql
#datadir=/var/lib/mysql (注释此行)
datadir=/home/data/mysql (加上此行)
7、重新启动MySQL服务
/etc/rc.d/init.d/mysql start
或用reboot命令重启Linux
增加MySQL用户
格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”
例1、增加一个用户user_1密码为123,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权
限。首先用以root用户连入MySQL,然后键入以下命令:
mysql>grant select,insert,update,delete on *.* to user_1@”%” Identified by “123″;
例1增加的用户是十分危险的,如果知道了user_1的密码,那么他就可以在网上的任何一台电脑上登录你的MySQL数据
库并对你的数据为所欲为了,解决办法见例2。
例2、增加一个用户user_2密码为123,让此用户只可以在localhost上登录,并可以对数据库aaa进行查询、插入、
修改、删除的操作(localhost指本地主机,即MySQL数据库所
在的那台主机),这样用户即使用知道user_2的密码,他也无法从网上直接访问数据库,只能通过 MYSQL主机来操作
aaa库。
mysql>grant select,insert,update,delete on aaa.* to user_2@localhost identified by “123″;
用新增的用户如果登录不了MySQL,在登录时用如下命令:
mysql -u user_1 -p -h 192.168.113.50 (-h后跟的是要登录主机的ip地址)
篇2:ubuntu 安装配置 mysql 详解教程linux操作系统
ubuntu 安装配置 mysql 详解教程 有需要的同学可参考一下,
ubuntu 安装配置 mysql
安装MySQL
代码如下复制代码sudo apt-get install mysql-server
设置Mysql中root用户的密码
默认的MySQL安装之后根用户没有密码:
mysql -u root一般来说,对mysql中的数据库进行操作,最好不要用根用户,只有在设置时才有这种可能。
代码如下复制代码mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456';
用root用户建立需要的数据库。以test为例:
代码如下复制代码mysql>CREATE DATABASE test;
mysql>GRANT ALL PRIVILEGES ON test.* TO test_root@localhost IDENTIFIED BY “test_passed”;
这样就建立了一个test_roots用户,它对数据库test有着全部权限。以后就可以用test_root来对test数据库进行管理,而无需要root用户了,而该用户的权限也被限定在test数据库中,
在Ubuntu下MySQL缺省是只允许本地访问的,如果需要其他主机也能够远程访问,需要添加权限并修改my.cnf配置文件
一、
代码如下复制代码mysql>GRANT ALL PRIVILEGES ON test.* TO 'test_root'@'%' IDENTIFIED BY 'test_passwd';允许test_root用户可以从任意主机登入该mysql Server,允许访问的数据库为test。
如果将“test.*”换为“.*.”,即为全部的数据库;如果将'%'换为相应主机名,只有该主机可以访问。
二、
1、编辑my.cnf,默认为/etc/mydql/my.cnf。
老版本中注释掉skip-networking,新版本中注释掉bind-address = 127.0.0.1或者修改为0.0.0.0(或本机IP)。
代码如下复制代码# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.12、重启mysql
sudo /etc/init.d/mysql restart
篇3:linux中Virtualmin安装配置教程linux操作系统
我们在上篇文章已经安装Virtualmin的面板,下面我们就是开始进行最简单的配置过程,希望本文章对各位同学会带来帮助哦,
进入后台
你的IP地址或者是主机名:10000/
输入地址进入后是webmin的默认登录界面
帐号:root
密码:你的VPS的密码
进入后需要我们初始化Virtualmin
Introduction
提示一下内容:
This post-installation wizard allows you to configure Virtualmin optimally for your system. You can make selections depending on whether you want to host websites, email or databases, and based on your system's memory and CPU power.
To continue, click the Next button below. To skip it and use the default settings, click Cancel.
我们点击“next”进入下一步
Memory use
这里就是让我们选择是否使用Virtualmin libraries与邮件域名查询服务器,如果不需要默认就好了(默认是不使用的)
接着我们点击“next”
Virus scanning
这里是让我选择是否需要病毒扫描器,也是不需要的。如果你有特别需求可以开启的!
再次点击“next”
Spam filtering
SpamAssassin server是一个垃圾邮件过滤系统,看看你自己要不要搭建邮件服务器,搭建的还是有必要打开的!
依旧是“next”
Database servers
这里就是选择相应的数据库的时候了,其实也可以直接默认的,看看你需不需PostgreSQL数据库了,需要的就打开,不需要则点击“next”
MySQL password
这里就是至关重要的一步了,设置MySQL数据库的密码,
要记住,因为下面我们需要的!
输入要设置的Mysql的密码后,点击“next”
MySQL database size
这里就是让我们选择mysql数据库的占用大小,如果对mysql数据库没有特别大的需要,直接选择默认设置或者是256的那行!
选择好mysql数据库后点击“next”
最后一步就是设置“主域名服务器”,系统会对你设置的主域名服务器进行检查,这里我推荐直接在后面的“Skip check for resolvability”前方打上对勾就可跳过检查!
然后点击“next”进入下一步
最后一步就是选择密码的存储方式,我推荐选择webmin默认的,毕竟跟密码有关,所以还是选择强度大点的好!
我们已经配置好基本的设置,现在只需要点击“next”即可。
最后是我们选择相应的插件查看的两个页面,直接“next”就大功告成了!
让我们来看看virtualmin的界面:
从上面可以看出来,安装后近占用了少量的内存
篇4:Linux环境配置安装MySQL数据库linux操作系统
MySQL是可以用于任意平台的,下面我来给大家详细的一步步介绍Linux配置MySQL数据库服务器的方法,有需要学习的朋友可参考,
1、下载MySQL免安装版/二进制版软件(不用编译)
文件格式:MYSQL-VERSION-OS.tar.gz
2、创建MySQL组,建立MySQL用户并加入到mysql组中
(不同版本的Unix中,groupadd和useradd的语法可能会稍有不同。)
代码如下复制代码#groupadd mysql
#useradd -g mysql mysql
3、进入目录/usr/local,解压缩免安装版,并在此目录中建立名为mysql的软链接
代码如下复制代码#cd /usr/local
#gunzip < /path/to/MYSQL-VERSION-OS.tar.gz | tar xvf -
(该命令会在本目录下创建一个名为MYSQL-VERSION-OS的新目录。)
(使用GNU tar,则不再需要gunzip。你可以直接用下面的命令来解包和提取分发:
代码如下复制代码#>tar zxvf /path/to/mysql-VERSION-OS.tar.gz)
#ln -s MYSQL-VERSION-OS mysql
4、添加MySQL配置文件
如果你想要设置一个选项文件,使用support-files目录中的一个作为模板。在这个目录中有4个模板文件,是根据不同机器的内存定制的。
代码如下复制代码#cp support-files/my-medium.cnf /etc/my.cnf
(可能你需要用root用户运行这些命令。)
5、设定目录访问权限,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限
代码如下复制代码#cd mysql
#chown -R mysql .
#chgrp -R mysql .
#scripts/mysql_install_db –user=mysql
#chown -R root .
#chown -R mysql data
(注意以上命令中的” . “符号不能少。)
6、运行MySQL
代码如下复制代码#bin/mysqld_safe –user=mysql &
(如果没有问题的话,应该会出现类似这样的提示:
[1] 42264
代码如下复制代码# Starting mysqld daemon with databases from /usr/local/mysql/var
如果出现 mysql ended这样的语句,表示Mysql没有正常启动,你可以到log中查找问题,Log文件的通常在/etc/my.cnf中配置,
大多数问题是权限设置不正确引起的。 )
7、设置root密码。默认安装密码为空,为了安全你需要修改密码
代码如下复制代码#/usr/local/mysql/bin/mysqladmin -uroot password yourpassword
8、拷贝编译目录的一个脚本,设置开机自动启动
代码如下复制代码#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chmod 700 /etc/init.d/mysqld
#chkconfig –add mysqld
#chkconfig –level 345 mysqld on
9、启动mysqld服务
代码如下复制代码#service mysqld start
10、查看3306端口是否打开。要注意在防火墙中开放该端口
代码如下复制代码#netstat -atln
免安装版/二进制版安装基本命令概述:
代码如下复制代码shell>groupadd mysql
shell>useradd -g mysql mysql
shell>cd /usr/local
shell>gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
shell>ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
shell>cd mysql
shell>chown -R mysql .
shell>chgrp -R mysql .
shell>scripts/mysql_install_db –user=mysql
shell>chown -R root .
shell>chown -R mysql data
shell>bin/mysqld_safe –user=mysql &
篇5:ubuntu安装配置mysql
ubuntu安装配置mysql
本文只介绍最简单最基本的安装配置方法
1、安装
[plain]
sudo apt-get install mysql-server
在安装的过程中会出现设置mysql密码的界面,输入密码,点击确定即可,
检测是否安装成功:输入命令:netstat -tap|grep mysql,察看是否存在mysql服务
存在,说明安装成功。
2、配置
2.1开启远程访问
mysql默认是只有本地(127.0.01)访问的,不允许远程访问,开启办法为:
[plain]
sudo gedit /etc/mysql/my.cnf
打开mysql的配置文件,将bind-address=127.0.0.1注释掉
2.2设置mysql的字符集为utf8
首先登陆进mysql(假设我的mysql密码为1234)
[plain]
mysql -uroot -p1234
使用命令:show variables like 'character%'; 察看字符编码
在[client]和[mysql]添加:character-set-server=utf8
保存,
重启mysql:sudo restart mysql
介绍mysql的几个常用命令
一、库操作
1、、创建数据库
命令:create database <数据库名>数据库名>
例如:建立一个名为test的数据库
mysql>create database test;
2、显示所有的数据库
命令:show databases
mysql>show databases;
3、删除数据库
命令:drop database <数据库名>数据库名>
例如:删除名为 test的数据库
mysql>drop database test;
4、连接数据库
命令: use <数据库名>数据库名>
例如:如果test数据库存在,尝试存取它:
mysql>use test;
屏幕提示:Database changed
5、查看当前使用的数据库
mysql>select database;
6、当前数据库包含的表信息:
mysql>show tables;
篇6:通过homebrew安装、配置nginx、mysql、phpfpmlinux操作系统
本文章来给大家介绍通过homebrew安装、配置nginx、mysql、php-fpm实例,有举的同学可进入参考,
1.1、环境选择:
重新在mac上配置php,原本mac上就自带有apach、php以及pgsql,如果图简单的话,直接用就可以了,不过在安装前我仔细思考了一下几个问题:
选apache还是nginx:两个我了解的都比较少,相对而言我接触nginx比较多,服务器用的也是nginx,没办法谁叫nginx负载高呢。为了更好的接触nginx的环境,我决定还是统一下环境,方便今后使用,这是这次的主要关键;
安装php:Mac os自带了php,好像是5.3.8,版本比较落后,不过这不碍事,因为以前我都是通过php-osx by Liip来管理php,所以不担心版本问题。不过php-osx by Liip好像没有fmp相关的配置,这样我我要和nginx一起用的话就相对比较麻烦了,那我只能选择其他方案了
安装mysql:这个就没有什么好疑问的了,目前我肯定不会去用pgsql,毕竟没接触过,需要有学习成本的,所以我在这篇纪录中把关于pgsql的部分都去掉了
1.2、那该如何安装:
既然我否定了系统自带的环境,那么就要通过别的方式去安装了,比如说手动编译。如果是手动编译的话,那么就会遇到下面几个问题:
编译费事,php依赖那么多程序,一个个安装,太累!
如果以后更新怎么办?灾难!!
不过好在mac下有自己的第三方管理程序:homebrew,而且相对而言我觉得他可能在某些方面更优越于linux下的apt-get、yum。如果通过homebrew来安装、管理运行环境的话,至少可以解决我几个问题:
安装问题,我不用繁琐的去安装依赖程序
升级问题,只需要brew update一次升级所有程序
版本问题,homebrew版本更新比较及时,而apt-get、yum来说,今年用的基本是几年前的稳定版本了
OK,下面的安装都是基于 homebrew,如果不熟悉或者还没安装有 homebrew 的话,可以查看这篇关于:Mac开发者利器-Homebrew介绍及安装。
二、安装nginx
2.1、安装:
用 brew 一键安装 nignx:
1 brew install nginx
如果需要安装其他 nginx 的版本,可以 “brew edit nginx” 打开修改 nginx 的安装信息包 formula,默认会用 vi 打开,在文件开头处修改 nginx 相应版本的下载地址就行。
2.2、配置
brew 执行完后,nginx 就安装好了。可以用以下指令对 nginx 进行操作:
#打开 nginx
sudo nginx
#重新加载|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
打开 nginx 后,默认的访问端口 8080,如果要改为常用的 80 端口,则要修改 “/usr/local/etc/nginx/nginx.conf” 下监听(listen)端口值。
默认的文件访问目录(root)是 “/usr/local/Cellar/nginx/1.4.2/html”(这里的1.4.2是安装的nginx的版本,文件夹名以安装的nginx版本为准)。
2.3、把 nginx 设置为开机启动运行:
mkdir -p ~/Library/LaunchAgents/
cp /usr/local/Cellar/nginx/1.4.2/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
不过试了一下,不是超级用户登陆,而是普通用户登陆,并且监听的端口在1024以下的(例如把默认的8080端口改为了80端口),nginx 开机是启动不了。因此,要 nginx 开机启动的话,需要给予它管理员权限:
12 sudo chown root:wheel /usr/local/Cellar/nginx/1.4.2/bin/nginxsudo chmod u+s /usr/local/Cellar/nginx/1.4.2/bin/nginx
三、安装mysql
3.1、安装:
1 brew install mysql
homebrew安装的版本同样是当前最新的稳定版,安装的过程比较简单,不过初始化就相对麻烦很多了,这里我失败了很多次。
3.2、配置:
3.2.1、初始化
初始安装 mysql 的一些配置数据库(例如:information_schema、mysql)
sudo mysql_install_db
--verbose --user=`whoami`
--basedir=“$(brew --prefix mysql)”
--datadir=/usr/local/var/mysql
--tmpdir=/tmp
--explicit_defaults_for_timestamp
这里我遇到了两个问题,过程都没纪录,这里简单提下解决方案:
系统建议我添加“–explicit_defaults_for_timestamp”;
安装过程中会遇到几个error,说是db的几个文件不存在;
网上搜索了下,大多是建议将/usr/local/var/mysql这个目录修改下权限;
我操作后发现可能不是这样的,造成这个问题在于我在之前操作遇到了错误中止了,生成了一个不完整var目录,所以每次安装失败我就删除以下文件,重新初始化就好了
12 sudo rm /usr/local/opt/mysql/my.cnf sudo rm -R /usr/local/var/mysql/
待安装完毕后,会出现一大段mysql相关信息,运行下面的命令启动mysql
1 /usr/local/opt/mysql/bin/mysqld_safe &
执行完后,就可以在终端里运行 “mysql”,直接进入mysql数据库里。对,不用输入密码,可以直接连接,初始默认是可以匿名访问的。
3.2.2、修改密码
超级用户 “root” 也是没设密码,要设密码的话可以执行下面指令
1 /usr/local/opt/mysql/bin/mysqladmin -u root password 'new-password'
现在访问 mysql 还是不用密码就可以连接,如果要设置一些登陆密码的安全访问限制,则需执行下面的 mysql安全安装指令
1 /usr/local/opt/mysql/bin/mysql_secure_installation
主要是设置修改root密码(设置过了可以不用设置,略过)、删除匿名访问、删除root网络访问、删除test数据库。指令执行完后,登陆mysql就需要密码验证了
1 mysql -u root -p
3.3、开机启动mysql
mkdir -p ~/Library/LaunchAgents/
cp /usr/local/Cellar/mysql/5.6.13/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
至此,mysql安装完毕。
四、安装php、php-fpm…
4.1、安装
Mac是预装了php,不过很多扩展都没安装,目测最多只能在终端里执行下php指令,所以我选择重新安装php,
由于 brew 默认是没有 php 安装,所以要使用 “brew tap” 来安装 brew 的第三方程序包,这里使用 josegonzalez 的php安装包,具体操作如下:
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
执行完后,就可以用 brew 安装php了。这里php有几个版本可以安装,具体可以执行 “brew search php” 查看一下有什么php版本可以安装,一般会有“php52、php53、php54、php55”版本,我安装的是最新的php5.5版本。由于PHP5.5版本已经内嵌了 FPM(FastCGI Process Manager),在安装选项里标明就行,本人 php 的安装配置指令如下:
sudo brew install php55
--with-debug
--with-fpm
--with-gmp
--with-homebrew-openssl
--with-imap --with-intl
--with-libmysql
--without-bz2
--without-mysql
--without-pcntl
--without-pear
更多的安装选项可以通过 “brew options php55″ 查看。
提示:–with-cgi不能和–with-fpm一起安装,互相冲突
指令执行完后,php 跟 php-fpm 就安装好了。
4.2、配置
由于是重装php,之前系统预装的php还没卸载,因此在终端调用php时,还是以之前系统的php版本做解析,所以这里需要修改path,指定 php 的解析路径。在~/.bashrc(没有则创建)最后加入一行:
1 export PATH=“$(brew --prefix php54)/bin:$PATH”
添加之后再执行一下source,使之生效
1 source ./.profile
不存在这个文件的朋友请参照这片文章进行配置:Mac系统终端命令行不执行命令 总出现command not found解决方法
OK,php-fpm安装完成。
要修改配置 php 或者 php-fpm 的话,可以修改 “/usr/local/etc/php/5.5/php.ini” 、“/usr/local/etc/php/5.5/php-fpm.conf”。
详细配置方法可以参照相关资料:
php-fpm 启动参数及重要配置详解
Linux平滑编译升级php至5.5.0
启动 php-fpm 的话就直接在终端里执行 “php-fpm”,默认打开 php-fpm 会显示一个状态 shell 出来,也可以把 php-fpm 的配置文件里的 “daemonize = no” 改为 “daemonize = yes”,就会以后台守护进程的方式启动,对于刚修改的配置文件,可以执行 “php-fpm -t” 来检测配置有没有问题。
4.3、开机启动
开机启动 php-fpm(下面的 5.5.3 是当前安装 php 的具体版本号):
mkdir -p ~/Library/LaunchAgents/
cp /usr/local/Cellar/php54/5.5.3/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist
为了方便,写了个启动、关闭、重启 php-fpm 的 shell 脚本:
#!/bin/sh
param=$1
start()
{
fpms=`ps aux | grep -i “php-fpm” | grep -v grep | awk '{print $2}'`
if [ ! -n “$fpms” ]; then
php-fpm
echo “PHP-FPM Start”
else
echo “PHP-FPM Already Start”
fi
}
stop()
{
fpms=`ps aux | grep -i “php-fpm” | grep -v grep | awk '{print $2}'`
echo $fpms | xargs kill -9
for pid in $fpms; do
if echo $pid | egrep -q '^[0-9]+$'; then
echo “PHP-FPM Pid $pid Kill”
else
echo “$pid IS Not A PHP-FPM Pid”
fi
done
}
case $param in
'start')
start;;
'stop')
stop;;
'restart')
stop
start;;
*)
echo “Usage: ./phpfpm.sh start|stop|restart”;;
esac
五、设置 nginx 的 php-fpm 配置
在server块中添加解析文件类型“index index.html index.htm index.php;”
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
......
}
打开 nginx 默认注释掉的php location设置,修改如下(具体配置参数,例如路径,这里以我本地安装为准):
location ~ .*.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Library/WebServer/public_html$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
#include fcgi.conf;
}
修改目录用户、用户组:
sudo chown www:www /Library/WebServer/public_html
OK,这样就可以在访问目录下(默认是/Library/WebServer/public_html)执行 php 文件了。嗯,赶快输出一下 “phpinfo()” 吧~
phpinfo();
篇7:linux中redis安装配置linux操作系统
MySQL是关系型数据库,并不擅长分布式数据出路,因为它缺乏并行执行查询的能力,这时候,可以使用其他工具。如redis。
redis是非关系型数据库。Nosql的一个开源项目。对于简单的键值存储,在复制严重落后的非常高速的访问场景中可以使用redis替代mysql。
redis安装如下。
1、下载安装包,下载地址是servicestack。如我下载的版本是redis-2.0.2.rar。
2、解压文件到相应目录。可以看到解压后内有文件:
3、其中配置文件需要自己创建,现将源代码附在下面:
代码如下复制代码# Redis configuration file example# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
# You can specify a custom pid file location here.
pidfile /var/run/redis.pid
# Accept connections on the specified port, default is 6379
port 6379
# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for connections.
#
# bind 127.0.0.1
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 300
# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel debug
# Specify the log file name. Also 'stdout' can be used to force
# the demon to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile stdout
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT
# dbid is a number between 0 and 'databases'-1
databases 16
################################ SNAPSHOTTING #################################
#
# Save the DB on disk:
#
# save
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
save 900 1
save 300 10
save 60 10000
# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes
# The filename where to dump the DB
dbfilename dump.rdb
# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir ./
################################# REPLICATION #################################
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof
# If the master is password protected (using the “requirepass” configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth
################################## SECURITY ###################################
# Require clients to issue AUTH
before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# requirepass foobared
################################### LIMITS ####################################
# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limts.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 128
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory
############################## APPEND ONLY MODE ###############################
# By default Redis asynchronously dumps the dataset on disk. If you can live
# with the idea that the latest records will be lost if something like a crash
# happens this is the preferred way to run Redis. If instead you care a lot
# about your data and don't want to that a single record can get lost you should
# enable the append only mode: when this mode is enabled Redis will append
# every write operation received in the file appendonly.log. This file will
# be read on startup in order to rebuild the full dataset in memory.
#
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the “save” statements above to disable the dumps).
# Still if append only mode is enabled Redis will load the data from the
# log file at startup ignoring the dump.rdb file.
#
# The name of the append only file is “appendonly.log”
#
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
# log file in background when it gets too big.
appendonly no
# The fsync call tells the Operating System to actually write data on disk
# instead to wait for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only if one second passed since the last fsync. Compromise.
#
# The default is “always” that's the safer of the options. It's up to you to
# understand if you can relax this to “everysec” that will fsync every second
# or to “no” that will let the operating system flush the output buffer when
# it want, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting).
appendfsync always
# appendfsync everysec
# appendfsync no
############################### ADVANCED CONFIG ###############################
# Glue small output buffers together in order to send small replies in a
# single TCP packet. Uses a bit more CPU but most of the times it is a win
# in terms of number of queries per second. Use 'yes' if unsure.
glueoutputbuf yes
# Use object sharing. Can save a lot of memory if you have many common
# string in your dataset, but performs lookups against the shared objects
# pool so it uses more CPU and can be a bit slower. Usually it's a good
# idea.
#
# When object sharing is enabled (shareobjects yes) you can use
# shareobjectspoolsize to control the size of the pool used in order to try
# object sharing. A bigger pool size will lead to better sharing capabilities.
# In general you want this value to be at least the double of the number of
# very common strings you have in your dataset.
# www.111cn.net
# WARNING: object sharing is experimental, don't enable this feature
# in production before of Redis 1.0-stable. Still please try this feature in
# your development environment so that we can test it better.
# shareobjects no
# shareobjectspoolsize 1024
4、命令行进入安装目录下(或者配置环境变量),
如图,
5、另开一个cmd,输入redis_cli.exe -h 127.0.0.1 -p 6349。接下来,你就可以玩了。
篇8:Linux配置MySQL数据库详解linux操作系统
本文章来给Linux配置MySQL数据库过程与命令,希望此文章对各位同学有所帮助哦,
Linux系统下如何配置安装MySQL数据库,下面所用的distribution是Centos5.8。
1. yum安装 yum install mysql* 为了确保过程不出问题,我们用mysql*把相关的都装上
2. Linux系统有个好处就是它可以自动为我们装好mysql不像windows里要自己手动配置;上面装完后有如下提示:
3. 安装完后重启MySQL服务,可能会重启失败。出现错误
Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
解决办法
查看cat /etc/hosts 发现什么文件也没有,编辑内容相关配置,
vim /etc/hosts 输入以下内容:127.0.0.1localhost.localdomain localhost
然后重新启动MySQL
4. 重新启动后可以正常运行了,然后修改初始密码。刚装完是没有密码的,我们可以直接输入mysql登陆:
5. 测试正常运行后,我们退出来修改初始密码,改完后再直接输入mysql测试下:
6. 使用新设置的密码123456可以正常登陆:
以上就是Linux系统下配置安装MySQL的一些简单的步骤!
★linux中清空Mysql数据库ROOT密码教程linux操作系统
★linux下CentOS的系统安全配置详细教程linux操作系统
文档为doc格式