安装mysql数据库在linux系统中有两种安装方法,一种是编译安装mysql 另一种是 免编译式安装mysql了,希望下文对各位有帮助.
编译安装mysql
安装前准备:如果mysql用户不存在,那么添加mysql用户.
groupadd mysql
useradd -g mysql mysql
mysql编译安装
- wgethttp://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
- tar-zxvfmysql-5.1.70.tar.gz
- cdmysql-5.1.70
- yuminstallncursesncurses-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
- makeinstall
到此mysql就安装到了/usr/local/mysql路径下,下面开始mysql的配置工作.
安装mysql选项文件:
cp support-files/my-medium.cnf /etc/my.cnf
mysql设置开机自启动:
- cp-rsupport-files/mysql.server/etc/init.d/mysqld
- /sbin/chkconfig--delmysqld
- /sbin/chkconfig--addmysqld
配置权限表:
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:line260:my_print_defaults:commandnotfound
- /etc/init.d/mysqld:line263:my_print_defaults:commandnotfound
- /etc/init.d/mysqld:line270:@HOSTNAME@:commandnotfound
- /etc/init.d/mysqld:line279:@HOSTNAME@:commandnotfound
- /etc/init.d/mysqld:line292:cd:@prefix@:Nosuchfileordirectory
- StartingMySQLCouldn'tfindMySQLmanager(@bindir@/mysqlmanager)orserver(@bindir@/mysqld_safe)[FAILED]--phpfensi.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]:Enteringdirectory`/down/webinstall/mysql-5.1.57/mysql-test
- make[3]:Enteringdirectory`/down/webinstall/mysql-5.1.57/mysql-test
- make[3]:Nothingtobedonefor`install-exec-am.
- makeINSTALL_TO_DIR="/usr/local/mysql/mysql-test"install_test_files
- make[4]:Enteringdirectory`/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@hktools]#wgethttp://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
- [root@hktools]#tarzxfmysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
- [root@hktools]#mvmysql-5.6.16-linux-glibc2.5-x86_64/opt/
- [root@hkopt]#mvmysql-5.6.16-linux-glibc2.5-x86_64mysql
- [root@hkopt]#/usr/sbin/useraddmysql-s/sbin/nologin-M
- [root@hkopt]#cdmysql/
- [root@hkmysql]#/opt/mysql/scripts/mysql_install_db--basedir=/opt/mysql/--datadir=/opt/mysql/data--user=mysql
- [root@hkmysql]#mv/etc/my.cnf/etc/my.cnf.backup
- [root@hkmysql]#sed-i's#\#socket=.....#socket=/tmp/mysql.sock#g'my.cnf
- [root@hkmysql]#cp/opt/mysql/my.cnf/etc/my.cnf
- [root@hkmysql]#/opt/mysql/support-files/mysql.serverstart
- [root@hkmysql]#netstat-tunlp
- ActiveInternetconnections(onlyservers)
- ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programname
- tcp00:::3306:::*LISTEN28104/mysqld
- [root@hkmysql]#/opt/mysql/bin/mysql-uroot-p
- Enterpassword:
- ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysql.sock'(2)#看下面的sock的配置
- [root@hkmysql]#sed-i's#\#socket=.....#socket=/tmp/mysql.sock#g'my.cnf
- [root@hkmysql]#/opt/mysql/bin/mysql-uroot-p
- Enterpassword:
- ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES)#居然报错
- [root@hkmysql]#/opt/mysql/bin/mysqld_safe--skip-grant-tables&
- [1]30062
- mysql>updatemysql.usersetpassword=PASSWORD('admin123')whereuser='root';#设置密码
- mysql>flushprivileges;
- [root@hkmysql]#skill30194
- [root@hkmysql]#14060100:14:38mysqld_safemysqldfrompidfile/opt/mysql/data/hk.t4x.org.pidended
- [1]+Done/opt/mysql/bin/mysqld_safe--skip-grant-tables
- [root@hkmysql]#/opt/mysql/bin/mysql-uroot-p
- Enterpassword:
- ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES)#错误依旧
- [root@hkmysql]#vim/usr/local/mysql/support-files/mysql.server#配置文件中默认配置目录是/usr/local/mysql
- [root@hkmysql]#ln-s/opt/mysql/usr/local/mysql#设置软连接
- [root@hkmysql]#/usr/local/mysql/bin/mysql-uroot-p'admin123'
- mysql>