Linux 下安装mysql (以mysql-5.0.22.tar.gz为例)
在Linux下安装mysql,其中走了不少弯路,在此记下:1.下载mysql-5.0.22.tar.gz 创建用户和用户组 [root@localhost usr]# groupadd mysql [root@localhost usr]# useradd -g mysql mysql 解压 [root@localhost usr]# gunzip -c m
在Linux下安装mysql,其中走了不少弯路,在此记下:
1.下载mysql-5.0.22.tar.gz
创建用户和用户组
[root@localhost usr]# groupadd mysql
[root@localhost usr]# useradd -g mysql mysql
解压
[root@localhost usr]# gunzip -c mysql-5.0.22.tar.gz |tar -xf -
因为用的是源代码,所以要把文件copy到安装目录/usr/local/下,才能运行查看系统有没有安装过mysql,查找rpm,如下:
[root@localhost mysql]# rpm –qa | grep mysql
有的话一个一个删除掉,用rpm -e命令,然后查找一下残留的文件:
[root@localhost mysql]# cd /
[root@localhost /]# find / -name mysql
如果查找到rm -rf filename删除.
[root@localhost /]# find / -name my.cnf
如果查找到删除,一般my.cnf是在/etc/my.cnf这里.
#./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-ndb-debug
郁闷,执行这一步竟然说
configure: error: no acceptable C compiler found in $PATH
与是下载了一个gcc-3.2.2-5.i386.rpm
执行如下命令安装:
rpm -ivh gcc-3.2.2-5.i386.rpm
接着./configure
又出现:
configure: error: No curses/termcap library found
说明 curses/termcap 库没有安装
去下载一个ncurses-5.6.tar.gz,
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure --prefix=/usr --with-shared --without-debug
make
make install clean
ok
然后再重新配置Mysql进行安装
make #时间有点长
make install clean
cp support-files/my-medium.cnf /etc/my.cnf #如果/etc/my.cnf已存在,则先备份,再删除
vi /etc/my.cnf #将log-bin=mysql-bin注释掉
bin/mysql_install_db --user=mysql #初始化mysql
chown -R root . #改当前目录的捅有者为root。注意,最后有个 . 啊,表示当前目录
chown -R mysql /usr/local/mysql-5.0.45/var #-R表示递归之下的所有目录
chgrp -R mysql /usr/local/mysql-5.0.45 #改变目录所属为mysql
bin/mysqld_safe --user=mysql & #启动mysql
初始化mysql:
bin/mysql_install_db --user=mysql
更新mysql密码:
[root@localhost mysql]# ./bin/mysqladmin -u root -h localhost.localdomain password 123456
[root@localhost mysql]# ./bin/mysqladmin -u root password 123456
登陆mysql:
[root@localhost mysql]# ./bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2 to server version: 5.0.22-enterprise-gpl
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> #启动mysql成功
查看3306端口是否打开:
[root@localhost /]# netstat -na|grep 3306
让Linux开放3306端口:
service iptables stop
vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables start
授权mysql远程连接:
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
关闭mysql数据库服务:
[root@localhost mysql]# ./bin/mysqladmin -u root shutdown
重新启动mysql:
/etc/init.d/mysqld restart
把mysql加入到系统服务中(就不用像上面那样启动mysql服务了):
[root@localhost /]# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
[root@localhost /]# chkconfig -add mysqld
把mysql加入到环境变量里面:
cp /usr/local/mysql/bin/mysql /usr/bin/mysql #这样就可以直接使用mysql命令了
更多推荐
所有评论(0)