安装和配置MySQL数据库服务器模块Lab1:源码安装MySQL服务器实验要求:1)通过源码安装MySQL服务器,要求安装到/usr/local/mysql目录,配置文件目录为/etc。
2)设置开机时自动运行MySQL服务器。
3)关闭rpm软件安装MySQL服务器(如果存在)。
实验时间:60分钟实验步骤:1、进入/root/lamp_software目录,找到mysql-6.0.4-alpha.tar.gz,并解压源码文件。
如下所示。
[root@localhost lamp_software]#tar-zxf mysql-6.0.4-alpha.tar.gz-C/usr/local[root@localhost lamp_software]#cd/usr/local/[root@localhost local]#lsbin games lib mysql-6.0.4-alpha sbin srcetc include libexec RealPlayer share2、配置mysql源码安装文件,设置MySQL安装到/usr/local/mysql目录,配置文件目录为/etc/目录。
[root@localhost local]#cd mysql-6.0.4-alpha[root@localhost mysql-6.0.4-alpha]#./configure--prefix=/usr/local/mysql--sysconfdir=/etc/3、编译mysql源码[root@localhost mysql-6.0.4-alpha]#make显示以下信息,表示编译成功。
/bin/chmod+x bench-count-distinct-t/bin/mv bench-count-distinct-t bench-count-distinctmake[1]:Leaving directory`/usr/local/mysql-6.0.4-alpha/sql-bench'Making all in winmake[1]:Entering directory`/usr/local/mysql-6.0.4-alpha/win'make[1]:Nothing to be done for`all'.make[1]:Leaving directory`/usr/local/mysql-6.0.4-alpha/win'4、安装mysql服务器[root@localhost mysql-6.0.4-alpha]#make install显示以下信息,表示编译成功。
make[2]:Leaving directory`/usr/local/mysql-6.0.4-alpha/sql-bench'make[1]:Leaving directory`/usr/local/mysql-6.0.4-alpha/sql-bench'Making install in winmake[1]:Entering directory`/usr/local/mysql-6.0.4-alpha/win'make[2]:Entering directory`/usr/local/mysql-6.0.4-alpha/win'make[2]:Nothing to be done for`install-exec-am'.make[2]:Nothing to be done for`install-data-am'.make[2]:Leaving directory`/usr/local/mysql-6.0.4-alpha/win'make[1]:Leaving directory`/usr/local/mysql-6.0.4-alpha/win'5、创建MySQL用户,并停止rpm包安装的MySQL服务器,如果用户存在可省略此步骤。
[root@localhost local]#service mysqld stop[root@localhost local]#chkconfig mysqld off[root@localhost local]#useradd–d/home/mysql mysql6、设置mysql权限,并初始化MySQL数据库。
[root@localhost local]#chown-R mysql.mysql/usr/local/mysql[root@localhost local]#su-mysql[mysql@localhost~]$sh bin/mysql_install_dbInstalling MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER!To do so,start the server,then issue the following commands:/usr/local/mysql/bin/mysqladmin-u root password'new-password'/usr/local/mysql/bin/mysqladmin-u root-h localhost.localdomain password'new-password'Alternatively you can run:/usr/local/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd/usr/local/mysql;/usr/local/mysql/bin/mysqld_safe&You can test the MySQL daemon with mysql-test-run.plcd/usr/local/mysql/mysql-test;perl mysql-test-run.plPlease report any problems with the/usr/local/mysql/bin/mysqlbug script!The latest information about MySQL is available at /Support MySQL by buying support/licenses from /7、启动mysql数据库[root@localhost~]$/usr/local/mysql/bin/mysqld_safe&[root@localhost~]$exit8、查看mysql数据库是否启动成功,显示端口为3306时,表示启动成功。
[root@localhost local]#netstat-antup|grep3306tcp000.0.0.0:33060.0.0.0:*LISTEN18208/mysqld9、测试MySQL数据库。
[root@localhost mysql]#mysqladmin–u root password‘51stc’//更改MySQL管理员密码。
[root@localhost local]#su–mysql//切换到MySQL用户。
[mysql@localhost~]$mysql-u root-p//登录MySQL数据库。
Enter password://输入刚刚更改密码,登录MySQL数据库。
Welcome to the MySQL mands end with;or\g.Your MySQL connection id is1Server version:6.0.4-alpha Source distributionType'help;'or'\h'for help.Type'\c'to clear the buffer.mysql>show databases;//显示MySQL数据库+--------------------+|Database|+--------------------+|information_schema||mysql||test|+--------------------+3rows in set(0.00sec)mysql>\s//显示MySQL数据库的状态信息。
--------------mysql Ver14.14Distrib6.0.4-alpha,for redhat-linux-gnu(i686)using EditLine wrapperConnection id:1Current database:Current user:root@localhostSSL:Not in useCurrent pager:stdoutUsing outfile:''Using delimiter:;Server version: 6.0.4-alpha Source distributionProtocol version:10Connection:Localhost via UNIX socketServer characterset:latin1Db characterset:latin1Client characterset:latin1Conn.characterset:latin1UNIX socket:/tmp/mysql.sockUptime:1min13secThreads:1Questions:5Slow queries:0Opens:15Flush tables:1Open tables:8 Queries per second avg:0.68--------------mysql>\q//退出Bye[root@localhost~]$exit//退回到root用户模式。