|
一、安装mysql数据库之前的准备
1.创建一个mysql用户组
1
[iyunv@taokey ~]# groupadd mysql
2.创建MySQL数据库的系统用户,加入到mysql组,不创建mysql家目录,禁止登陆系统
1
[iyunv@taokey ~]# useradd -s /sbin/nologin -g mysql -M mysql
创建一个专门存放mysql压缩包的目录,/taokey/tools
1
[iyunv@taokey ~]# mkdir -p /taokey/tools
把压缩包移到指定目录/taokey/tools下
1
[iyunv@taokey ~]# mv mysql-5.1.65.tar.gz /taokey/tools/
二、编译安装mysql5.1.65数据库
把压缩包移到指定目录/taokey/tools下,进到压缩包所在的目录,进行解压。
[iyunv@taokey ~]# mv mysql-5.1.65.tar.gz /taokey/tools/
[iyunv@taokey ~]# cd /taokey/tools/
[iyunv@taokey tools]# tar -zxvf mysql-5.1.65.tar.gz
[iyunv@taokey tools]# cd mysql-5.1.65
注意:make的时候,会报错:
##编辑configure,删除$RM "$cfgfile"这一行
[iyunv@taokey mysql-5.1.65]# vim configure
删除掉 $RM "$cfgfile" //52297行
指定并且编辑mysql安装文件,以及相关参数
1
[iyunv@taokey mysql-5.1.65]#./configure --prefix=/application/mysql5.1.65 --with-unix-socket-path=/application/mysql5.1.65/tmp/mysql.sock --localstatedir=/application/mysql5.1.65/data --enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --enable-assembler --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase --with-plugin-PLUGIN --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
静态编译生成的mysqld的执行文件
[iyunv@taokey mysql-5.1.65]#make
make[2]: Leaving directory `/taokey/tools/mysql-5.1.65/server-tools/instance-manager'
make[1]: Leaving directory `/taokey/tools/mysql-5.1.65/server-tools'
Making all in win
make[1]: Entering directory `/taokey/tools/mysql-5.1.65/win'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/taokey/tools/mysql-5.1.65/win'
没有报错,error之类的错误,就说明make成功了
安装mysql.
[iyunv@taokey mysql-5.1.65]#make install
make[1]: Entering directory `/taokey/tools/mysql-5.1.65/win'
make[2]: Entering directory `/taokey/tools/mysql-5.1.65/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 `/taokey/tools/mysql-5.1.65/win'
make[1]: Leaving directory `/taokey/tools/mysql-5.1.65/win'
没有报错,error之类的错误,就说明make install安装成功了
安装成功之后,下边配置mysql,使之可以正常启动
需要拷贝一个mysql的主配置文件,这个是必须拷贝的,我这里复制了一个small
1
[iyunv@taokey mysql-5.1.65]#cp support-files/my-small.cnf /etc/my.cnf
做一个软连接/application/mysql5.1.65的软连接,名字为/application/mysql
1
[iyunv@taokey mysql-5.1.65]#ln -s /application/mysql5.1.65 /application/mysql
查看下做的软连接是否生效
1
[iyunv@taoyake mysql5.1.65]# ls -ld /application/mysql
1
lrwxrwxrwx 1 root root 24 Jan 23 19:48 /application/mysql -> /application/mysql5.1.65
创建一个date目录,用于存放mysql数据
1
[iyunv@taoyake mysql5.1.65]#mkdir -p /application/mysql/data
初始化数据库
1
[iyunv@taokey mysql-5.1.65]#/application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
拷贝脚本到/etc/init.d/这个目录下,名字为mysqd 方便以后启动
[iyunv@taokey mysql-5.1.65]# cp support-files/mysql.server /etc/init.d/mysqld
设置mysqld权限700,出于安全考虑
[iyunv@taokey mysql-5.1.65]# chmod 700 /etc/init.d/mysqld
设置mysql属组的权限可以执行/application/mysql/bin/mysql的命令
[iyunv@taokey mysql-5.1.65]# chown -R root.mysql /application/mysql/bin/mysql
[iyunv@taokey mysql-5.1.65]# echo "/application/mysql/lib/mysql" >> /etc/ld.so.conf
[iyunv@taokey mysql-5.1.65]# ldconfig
开启数据库
[iyunv@taoyake mysql-5.1.65]# /application/mysql/bin/mysqld_safe --user=mysql &
130123 19:43:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql5.1.65/data
[iyunv@taokey mysql-5.1.65]# netstat -natp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 14003/mysqld
使mysqld脚本有执行权限
[iyunv@taokey mysql-5.1.65]# chmod +x /etc/init.d/mysqld
[iyunv@taokey mysql-5.1.65]# chkconfig --add mysqld
[iyunv@taokey mysql-5.1.65]# chkconfig mysqld on
设置一下mysql数据库的变量
[iyunv@taokey mysql-5.1.65]# export PATH=$PATH:/application/mysql/bin
为了永久生效,我们可以让变量追加到etc/profile
[iyunv@taokey mysql-5.1.65]# echo "PATH=$PATH:/application/mysql/bin" >>/etc/profile
用source命令,可以使变量马上生效
[iyunv@taokey mysql-5.1.65]# source /etc/profile
直接使用mysql就可以登录数据库(无需密码,因为还没有设置密码)
[iyunv@taoyake mysql-5.1.65]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.65 Source distribution
Copyright (c) 2000, 2011, 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数据库,就是下边的这么标志;
mysql>
退出mysql数据库,当然也可以使用quit退出数据库
mysql> exit
Bye
[iyunv@taokey mysql-5.1.65]#
设置mysql的root密码;
[iyunv@taokey mysql-5.1.65]# mysqladmin -uroot password '123.com'
用root用户,以及刚刚设置的密码登录数据库
[iyunv@taokey mysql-5.1.65]# mysql -uroot -p123.com
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.65 Source distribution
Copyright (c) 2000, 2011, 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>
|
|