1、这里使用的是解压包;解压完成后直接配置即可使用
配置前先准备已下工作
[Linux88]#groupadd -r mysql
[Linux88]#useradd -r -g mysql -s /sbin/nologin mysql
#先创建一个逻辑卷;这里就不演示创建逻辑卷的过程了;逻辑卷也不是实验必须创建的;实验时可以不用创建
[Linux88]#df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/sqlvg-lvsql ext4 9.9G 151M 9.2G 2% /Mysql/data
#
配置mysql
#解压到指定路径
[Linux88]#tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[Linux88]#cd /usr/local/
[Linux88]#ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64/ /usr/local/mysql
`/usr/local/mysql' -> `/usr/local/mysql-5.5.33-linux2.6-x86_64/'
[Linux88]#cd mysql
[Linux88]#chown -R root.mysql *
#初始化数据库;并指定其用户和data目录
[Linux88]#scripts/mysql_install_db --user=mysql --datadir=/Mysql/data
[Linux88]#ls /Mysql/data/
lost+found mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index performance_schema test
#没有报错并生成以上文件即可
[Linux88]#cp support-files/my-large.cnf /etc/my.cnf 配置一个配置文件
[Linux88]#vi /etc/my.cnf 更改已下配置选项;具体选项根据自己需要配置
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
datadir = /Mysql/data 新增一行
提供一个服务脚本
[Linux88]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[Linux88]#chmod +x /etc/rc.d/init.d/mysqld
[Linux88]#chkconfig --add mysqld
[Linux88]#chkconfig mysqld on
[Linux88]#chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[Linux88]#service mysqld start
Starting MySQL... [ OK ]
#启动成功后导出其他信息
[Linux88]#vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[Linux88]#ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include/'
[Linux88]#
[Linux88]#vi /etc/man.config
定位到MANPATH
#
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /usr/local/mysql/man #添加一行
#
[Linux88]#echo /usr/local/mysql/lib/ > /etc/ld.so.conf.d/mysql.conf
2、配置MySQL整合PHP
[Linux88]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>use mysql 授权表
mysql> select user,host,password from user;
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | localhost | |
| root | localhost.localdomain | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | localhost.localdomain | |
+------+-----------------------+----------+
6 rows in set (0.00 sec)
mysql> update user set password = password ('you_passwd') where user='root';
#更改user表中所有用户为root的密码
mysql> drop user ''@'localhost.localdomain'; 删除一些无用的账户;以保证安全性
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4 Changed: 0 Warnings: 0
mysql> select user,host,password from user; 显示user的信息;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
| root | localhost.localdomain | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
| root | 127.0.0.1 | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
+------+-----------------------+-------------------------------------------+
3 rows in set (0.00 sec)
#下面的较为重要;这是授权PHP主机可以访问的
mysql> grant all privileges on *.* to 'root'@'172.16.251.87' identified by 'you passwd';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
| root | localhost.localdomain | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
| root | 127.0.0.1 | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
| root | 172.16.251.87 | *4B78DCD8C21610F21CBEA871E687A33647CF8EE4 |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> flush privileges; 更新
Query OK, 0 rows affected (0.00 sec)
mysql>
到此以完成授权;下面就整合测试WordPress和phpmyadmin。
四、测试LAMP
1、先测试在php主机上是否可以连接mysql
[Linux87]#vim index.php
<?php
$link = mysql_connect('172.16.251.88','root','you_passwd');
if($link)
echo "Success...";
else
echo "Failed....";
mysql_close;
phpinfo();
?>
~
能看到左上角有Success说明连接成功;也可以停止mysql服务测试看下。