安装mysql数据库在linux系统中有两种安装方法,一种是编译安装mysql 另一种是 免编译式安装mysql了,希望下文对各位有帮助.
编译安装mysql
安装前准备:如果mysql用户不存在,那么添加mysql用户.
groupadd mysql
useradd -g mysql mysql
mysql编译安装
- wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
- tar -zxvf mysql-5.1.70.tar.gz
- cd mysql-5.1.70
- yum install ncurses ncurses-devel
- ./configure '--prefix=/usr/local/mysql' '--without-debug' '--with-charset=utf8' '--with-extra-charsets=all' '--enable-assembler' '--with-pthread' '--enable-thread-safe-client' '--with-mysqld-ldflags=-all-static' '--with-client-ldflags=-all-static' '--with-big-tables' '--with-readline' '--with-ssl' '--with-embedded-server' '--enable-local-infile' '--with-plugins=innobase'
- make
- make install
到此mysql就安装到了/usr/local/mysql路径下,下面开始mysql的配置工作.
安装mysql选项文件:
cp support-files/my-medium.cnf /etc/my.cnf
mysql设置开机自启动:
- cp -r support-files/mysql.server /etc/init.d/mysqld
- /sbin/chkconfig --del mysqld
- /sbin/chkconfig --add mysqld
配置权限表:
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
启动mysql:/etc/init.d/mysqld start
这一步可能会报错:
- /etc/init.d/mysqld: line 260: my_print_defaults: command not found
- /etc/init.d/mysqld: line 263: my_print_defaults: command not found
- /etc/init.d/mysqld: line 270: @HOSTNAME@: command not found
- /etc/init.d/mysqld: line 279: @HOSTNAME@: command not found
- /etc/init.d/mysqld: line 292: cd: @prefix@: No such file or directory
- Starting MySQLCouldn't find MySQL manager (@bindir@/mysqlmanager) or server (@bindir@/mysqld_safe) [FAILED] --Vevb.com
因为路径没有设置,请重启确认上面配置工作是否都完成,一般是configure后没有make和make install.
mysql初始化配置:
export PATH=/usr/local/mysql/bin:$PATH
/usr/local/mysql/bin/mysql_secure_installation
mysql如何导入旧的数据:
直接拷贝数据库文件夹到数据目录下然后执行
/usr/local/mysql/bin/mysqladmin -u root -p flush-tables
mysql安装过程中问题:
- make[2]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
- make[3]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
- make[3]: Nothing to be done for `install-exec-am.
- make INSTALL_TO_DIR="/usr/local/mysql/mysql-test" install_test_files
- make[4]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
时间较长:MYSQL安装到这里卡了很久,可能以为出错了,实际上MYSQL已经安装成功了,它这步过段时间就会好了,是mysql在自我编译测试造成的.
2.checking for termcap functions library... configure: error: No curses/termcap library found
yum install ncurses ncurses-devel
3.Starting MySQL.Manager of pid-file quit without updating fi[FAILED]
启动数据库之前,需要先配置权限表,其中/usr/local/mysql为mysql的安装目录.
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
上面安装mysql是通过编译的方式安装,此次不进行编译,直接安装.
- [root@hk tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
- [root@hk tools]# tar zxf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
- [root@hk tools]# mv mysql-5.6.16-linux-glibc2.5-x86_64 /opt/
- [root@hk opt]# mv mysql-5.6.16-linux-glibc2.5-x86_64 mysql
- [root@hk opt]# /usr/sbin/useradd mysql -s /sbin/nologin -M
- [root@hk opt]# cd mysql/
- [root@hk mysql]# /opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql/ --datadir=/opt/mysql/data --user=mysql
- [root@hk mysql]# mv /etc/my.cnf /etc/my.cnf.backup
- [root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf
- [root@hk mysql]# cp /opt/mysql/my.cnf /etc/my.cnf
- [root@hk mysql]# /opt/mysql/support-files/mysql.server start
- [root@hk mysql]# netstat -tunlp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 :::3306 :::* LISTEN 28104/mysqld
- [root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
- Enter password:
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) #看下面的sock的配置
- [root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf
- [root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
- Enter password:
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) #居然报错
- [root@hk mysql]# /opt/mysql/bin/mysqld_safe --skip-grant-tables &
- [1] 30062
- mysql> update mysql.user set password=PASSWORD('admin123') where user='root'; #设置密码
- mysql> flush privileges;
- [root@hk mysql]# skill 30194
- [root@hk mysql]# 140601 00:14:38 mysqld_safe mysqld from pid file /opt/mysql/data/hk.t4x.org.pid ended
- [1]+ Done /opt/mysql/bin/mysqld_safe --skip-grant-tables
- [root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
- Enter password:
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) #错误依旧
- [root@hk mysql]# vim /usr/local/mysql/support-files/mysql.server #配置文件中默认配置目录是/usr/local/mysql
- [root@hk mysql]# ln -s /opt/mysql /usr/local/mysql #设置软连接
- [root@hk mysql]# /usr/local/mysql/bin/mysql -uroot -p'admin123'
- mysql>
新闻热点
疑难解答