GVKun编程网logo

Linux下mysql数据库文件全部丢失mysql无法启动

4

本篇文章给大家谈谈Linux下mysql数据库文件全部丢失mysql无法启动,同时本文还将给你拓展linux–重定位数据后,mysql无法启动、linux下mysql无法启动mysql.sock、Li

本篇文章给大家谈谈Linux下mysql数据库文件全部丢失mysql无法启动,同时本文还将给你拓展linux – 重定位数据后,mysql无法启动、linux 下mysql无法启动 mysql.sock、Linux下mSQL数据库设计技术_MySQL、Linux下MySQL 3数据库升级到MySQL 4.1乱码问题的完美解决等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Linux下mysql数据库文件全部丢失mysql无法启动

Linux下mysql数据库文件全部丢失mysql无法启动

一早起来,发现数据目录下的MysqL文件全部消失,一声冷汗,怎么回事!!???被黑了,还是因为前两天重启服务器导致MysqL数据丢失???这是怎么回事,上网看看怎么解决,没找到解决方案!!!!看看MysqL服务是不是开启的,

[root@pacteralinux MysqL]# ps -ef|grep MysqL root 53794291013:10pts/000:00:00grep MysqL [root@pacteralinux MysqL]# service MysqLd start Starting MysqL..The server quit without updating PID file (/mnt/resource/MysqLdate/pacteralinux.pid).[Failed]

,服务关闭,而且启动不了!看日志:

13112613:10:57MysqLd_safe Starting MysqLd daemon withdatabases from /mnt/resource/MysqLdate 2013-11-2613:10:580[Warning] TIMESTAMP withimplicit DEFAULT value isdeprecated. Pleaseuse--explicit_defaults_for_timestamp server option (see documentation formore details). 2013-11-2613:10:585650[Note] Plugin 'FEDERATED'isdisabled. /usr/local/MysqL/bin/MysqLd: Table 'MysqL.plugin'doesn't exist 2013-11-2613:10:585650[ERROR] Can't open the MysqL.plugin table. Please run MysqL_upgrade to create it. 2013-11-2613:10:585650[Note] InnoDB: The InnoDB memory heap isdisabled 2013-11-2613:10:585650[Note] InnoDB: Mutexes and rw_locks useGCC atomic builtins 2013-11-2613:10:585650[Note] InnoDB: Compressed tables usezlib 1.2.3 2013-11-2613:10:585650[Note] InnoDB: Not using cpu crc32 instructions 2013-11-2613:10:585650[Note] InnoDB: Initializing buffer pool,size = 128.0M 2013-11-2613:10:585650[Note] InnoDB: Completed initialization of buffer pool 2013-11-2613:10:585650[Note] InnoDB: The first specified data file ./ibdata1 did not exist: a newdatabase to be created! 2013-11-2613:10:585650[Note] InnoDB: Setting file ./ibdata1 size to 12MB 2013-11-2613:10:585650[Note] InnoDB: Database physically writes the file full: wait... 2013-11-2613:10:585650[Note] InnoDB: Setting log file ./ib_logfile101 size to 48MB 2013-11-2613:10:585650[Note] InnoDB: Setting log file ./ib_logfile1 size to 48MB 2013-11-2613:10:585650[Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2013-11-2613:10:585650[Warning] InnoDB: New log files created,LSN=45781 2013-11-2613:10:585650[Note] InnoDB: Doublewrite buffer not found: creating new 2013-11-2613:10:585650[Note] InnoDB: Doublewrite buffer created 2013-11-2613:10:585650[Note] InnoDB: 128rollback segment(s) are active. 2013-11-2613:10:595650[Warning] InnoDB: Creating foreign key constraint system tables. 2013-11-2613:10:595650[Note] InnoDB: Foreign key constraint system tables created 2013-11-2613:10:595650[Note] InnoDB: Creating tablespace and datafile system tables. 2013-11-2613:10:595650[Note] InnoDB: Tablespace and datafile system tables created. 2013-11-2613:10:595650[Note] InnoDB: Waiting forpurge to start 2013-11-2613:10:595650[Note] InnoDB: 5.6.14started; log sequence number 0 2013-11-2613:10:595650[Note] Server hostname (bind-address): '*'; port: 3306 2013-11-2613:10:595650[Note] IPv6 isavailable. 2013-11-2613:10:595650[Note] - '::'resolves to '::'; 2013-11-2613:10:595650[Note] Server socket created on IP: '::'. 2013-11-2613:10:595650[ERROR] Fatal error: Can't open and lock privilege tables: Table 'MysqL.user' doesn't exist 13112613:10:59MysqLd_safe MysqLd from pid file /mnt/resource/MysqLdate/pacteralinux.pid ended [ERROR] Fatal error: Can't open and lock privilege tables: Table 'MysqL.user' doesn't exist:

表初始化没做好;不管,下意识的删除日志看下能不能重启

[root@pacteralinux MysqLdate]# lltotal 110640-rw-rw----. 1MysqL MysqL 56Nov 2517:17auto.cnf-rw-rw----. 1MysqL MysqL 12582912Nov 2613:15ibdata1-rw-rw----. 1MysqL MysqL 50331648Nov 2613:15ib_logfile0-rw-rw----. 1MysqL MysqL 50331648Nov 2613:10ib_logfile1-rw-rw----. 1MysqL root 39056Nov 2613:15pacteralinux.err[root@pacteralinux MysqLdate]# rm ib*rm: remove regular file `ibdata1'? yrm: remove regular file `ib_logfile0'? yrm: remove regular file `ib_logfile1'? y
1234567891011

不行,网上看看能不能恢复数据,无解决方案!!

幸好这时一个MysqL从服务器(我做了一个主从MysqL热备份)!!!没办法,数据恢复不了就重新在复制一份吧!

上述步骤后还是不能启动数据

试试重新初始化:

[root@pacteralinux MysqLdate]# /usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL/data/ --datadir=/mnt/resource/MysqLdate/ Fatal error: Could not find ./bin/my_print_defaults If you compiled from source,you need to run 'make install'to copy the software into the correct location ready foroperation. If you are using a binary release,you must either be at the top level of the extracted archive,or pass the --basedir option pointing to that location. [root@pacteralinux MysqLdate]# cd /usr/local/MysqL/bin/ [root@pacteralinux MysqL]# /usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --no-defaults Installing MysqL system tables...2013-11-2613:20:420[Warning] TIMESTAMP withimplicit DEFAULT value isdeprecated. Please use--explicit_defaults_for_timestamp server option (see documentation formore details). 2013-11-2613:20:426036[Note] InnoDB: The InnoDB memory heap isdisabled 2013-11-2613:20:426036[Note] InnoDB: Mutexes and rw_locks useGCC atomic builtins 2013-11-2613:20:426036[Note] InnoDB: Compressed tables usezlib 1.2.3 2013-11-2613:20:426036[Note] InnoDB: Not using cpu crc32 instructions 2013-11-2613:20:426036[Note] InnoDB: Initializing buffer pool,size = 128.0M 2013-11-2613:20:426036[Note] InnoDB: Completed initialization of buffer pool 2013-11-2613:20:426036[Note] InnoDB: Highest supported file format isBarracuda. 2013-11-2613:20:426036[Note] InnoDB: 128rollback segment(s) are active. 2013-11-2613:20:426036[Note] InnoDB: Waiting forpurge to start 2013-11-2613:20:426036[Note] InnoDB: 5.6.14started; log sequence number 1600607 2013-11-2613:20:426036[Warning] InnoDB: Cannot open table MysqL/innodb_table_stats from theinternaldata dictionary of InnoDB though the .frm file forthe table exists. See http://dev.MysqL.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem. ERROR: 1146Table 'MysqL.innodb_table_stats'doesn't exist 2013-11-2613:20:426036[ERROR] Aborting 2013-11-2613:20:426036[Note] binlog end 2013-11-2613:20:426036[Note] InnoDB: FTS optimize thread exiting. 2013-11-2613:20:426036[Note] InnoDB: Starting shutdown... 2013-11-2613:20:446036[Note] InnoDB: Shutdown completed; log sequence number 1600617 2013-11-2613:20:446036[Note] ./bin/MysqLd: Shutdown complete

初始化不了,,删除之前初始化的文件试试

[root@pacteralinux data]# lltotal 12drwx------. 2MysqL MysqL 4096Sep 2512:27MysqLdrwx------. 2MysqL MysqL 4096Sep 2512:27performance_schemadrwxr-xr-x. 2MysqL MysqL 4096Sep 2510:28test[root@pacteralinux data]# cd ..[root@pacteralinux MysqL]# rm -rf data/
1234567

重新初始化:

[root@pacteralinux MysqL]# scripts/MysqL_install_db --basedir=/usr/local/MysqL --datadir=/mnt/resource/MysqLdate --user=MysqLInstalling MysqL system tables...2013-11-2613:41:480[Warning] TIMESTAMP withimplicit DEFAULT value isdeprecated. Please use--explicit_defaults_for_timestamp server option (see documentation formore details).2013-11-2613:41:486768[Note] InnoDB: The InnoDB memory heap isdisabled2013-11-2613:41:486768[Note] InnoDB: Mutexes and rw_locks useGCC atomic builtins2013-11-2613:41:486768[Note] InnoDB: Compressed tables usezlib 1.2.32013-11-2613:41:486768[Note] InnoDB: Not using cpu crc32 instructions2013-11-2613:41:486768[Note] InnoDB: Initializing buffer pool,size = 128.0M2013-11-2613:41:486768[Note] InnoDB: Completed initialization of buffer pool2013-11-2613:41:486768[Note] InnoDB: Highest supported file format isBarracuda.2013-11-2613:41:486768[Note] InnoDB: Log scan progressed past the checkpoint lsn 494632013-11-2613:41:486768[Note] InnoDB: Database was not shutdown normally!2013-11-2613:41:486768[Note] InnoDB: Starting crash recovery.2013-11-2613:41:486768[Note] InnoDB: Reading tablespace information from the .ibd files...2013-11-2613:41:486768[Note] InnoDB: Restoring possible half-written data pages2013-11-2613:41:486768[Note] InnoDB: from the doublewrite buffer...InnoDB: Doing recovery: scanned up to log sequence number 16006172013-11-2613:41:486768[Note] InnoDB: Starting an apply batch of log records to the database...InnoDB: Progress inpercent: 282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899InnoDB: Apply batch completed2013-11-2613:41:486768[Note] InnoDB: 128rollback segment(s) are active.2013-11-2613:41:486768[Note] InnoDB: Waiting forpurge to start2013-11-2613:41:486768[Note] InnoDB: 5.6.14started; log sequence number 16006172013-11-2613:41:546768[Note] binlog end2013-11-2613:41:546768[Note] InnoDB: FTS optimize thread exiting.2013-11-2613:41:546768[Note] InnoDB: Starting shutdown...2013-11-2613:41:556768[Note] InnoDB: Shutdown completed; log sequence number 1625997OKFilling help tables...2013-11-2613:41:550[Warning] TIMESTAMP withimplicit DEFAULT value isdeprecated. Please use--explicit_defaults_for_timestamp server option (see documentation formore details).2013-11-2613:41:556793[Note] InnoDB: The InnoDB memory heap isdisabled2013-11-2613:41:556793[Note] InnoDB: Mutexes and rw_locks useGCC atomic builtins2013-11-2613:41:556793[Note] InnoDB: Compressed tables usezlib 1.2.32013-11-2613:41:556793[Note] InnoDB: Not using cpu crc32 instructions2013-11-2613:41:556793[Note] InnoDB: Initializing buffer pool,size = 128.0M2013-11-2613:41:556793[Note] InnoDB: Completed initialization of buffer pool2013-11-2613:41:556793[Note] InnoDB: Highest supported file format isBarracuda.2013-11-2613:41:556793[Note] InnoDB: 128rollback segment(s) are active.2013-11-2613:41:556793[Note] InnoDB: Waiting forpurge to start2013-11-2613:41:556793[Note] InnoDB: 5.6.14started; log sequence number 16259972013-11-2613:41:556793[Note] binlog end2013-11-2613:41:556793[Note] InnoDB: FTS optimize thread exiting.2013-11-2613:41:556793[Note] InnoDB: Starting shutdown...2013-11-2613:41:576793[Note] InnoDB: Shutdown completed; log sequence number 1626007OKTo start MysqLd at boot time you have to copysupport-files/MysqL.server to the right place foryour systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MysqL root USER !To doso,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 pacteralinux 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 forproduction servers.See the manual formore instructions.You can start the MysqL daemon with:cd . ; /usr/local/MysqL/bin/MysqLd_safe &You can test the MysqL daemon withMysqL-test-run.plcd MysqL-test ; perl MysqL-test-run.plPlease report any problems withthe ./bin/MysqLbug script!The latest information about MysqL isavailable on the web athttp://www.MysqL.comSupport MysqL by buying support/licenses at http://shop.MysqL.comWARNING: Found existing config file /usr/local/MysqL/my.cnf on the system.Because thisfile might be inuse,it was not replaced,but was used inbootstrap (unless you used --defaults-file)and when you later start the server.The newdefaultconfig file was created as/usr/local/MysqL/my-new.cnf,please compare it withyour file and take the changes you need.WARNING: Default config file /etc/my.cnf exists on the systemThis file will be read by defaultby the MysqL serverIf you donot want to usethis,either remove it,or usethe--defaults-file argument to MysqLd_safe when starting the server
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273

重新启动MysqL

[root@pacteralinux scripts]# service MysqLd startStarting MysqL.[ OK ][root@pacteralinux MysqL]# ps -ef|grep msyqlroot 7236 4316 0 14:08 pts/100:00:00 grepmsyql[root@pacteralinux MysqL]# ps -ef|grep MysqLroot 6838 1 0 13:42 pts/100:00:00 /bin/sh/usr/local/MysqL/bin/MysqLd_safe--datadir=/mnt/resource/MysqLdate--pid-file=/mnt/resource/MysqLdate/pacteralinux.pidMysqL 7091 6838 0 13:42 pts/100:00:00 /usr/local/MysqL/bin/MysqLd--basedir=/usr/local/MysqL--datadir=/mnt/resource/MysqLdate--plugin-dir=/usr/local/MysqL/lib/plugin--user=MysqL --log-error=/mnt/resource/MysqLdate/pacteralinux.err --pid-file=/mnt/resource/MysqLdate/pacteralinux.pid --socket=/mnt/resource/MysqLdate/MysqL.sock --port=3306root 7238 4316 0 14:08 pts/100:00:00 grepMysqL
12345678

可以看到,MysqL安装路径为--basedir=/usr/local/MysqL,初始数据库的存放目录为--datadir=/mnt/resource/MysqLdate

-rw-rw----. 1 MysqL MysqL 2048 Nov 26 13:41 user.MYI[root@pacteralinux MysqL]# pwd/mnt/resource/MysqLdate/MysqL[root@pacteralinux MysqL]# cd ..[root@pacteralinux MysqLdate]# lltotal 110664-rw-rw----. 1 MysqL MysqL 56 Nov 25 17:17 auto.cnf-rw-rw----. 1 MysqL MysqL 12582912 Nov 26 13:42 ibdata1-rw-rw----. 1 MysqL MysqL 50331648 Nov 26 13:42 ib_logfile0-rw-rw----. 1 MysqL MysqL 50331648 Nov 26 13:39 ib_logfile1drwx------. 2 MysqL MysqL 4096 Nov 26 13:41 MysqLsrwxrwxrwx. 1 MysqL MysqL 0 Nov 26 13:42 MysqL.sock-rw-rw----. 1 MysqL root 46096 Nov 26 13:42 pacteralinux.err-rw-rw----. 1 MysqL MysqL 5 Nov 26 13:42 pacteralinux.piddrwx------. 2 MysqL MysqL 4096 Nov 26 13:41 performance_schemadrwx------. 2 MysqL MysqL 4096 Nov 26 13:41 test
12345678910111213141516

其中,MysqL,performance_schema,test为初始化后的文件

下面开始恢复数据库

登录到生产服务器执行备份:

[root@uyhd000225 ~]# MysqLdump -u***** -P***** MysqLdb >MysqLdb20131126.sql #数据库比较大,大约半小时
1

复制到备份服务器:

[root@uyhd000225 ~]# scp MysqLdb20131126.sql root@remoteIP:/mnt/backup/root@remoteIP's password:MysqLdb20131126.sql 3% 153MB 680.6KB/s 1:43:33ETA
123


本文出自 “从运维开始” 博客,请务必保留此出处http://fuwenchao.blog.51cto.com/6008712/1331822


linux – 重定位数据后,mysql无法启动

linux – 重定位数据后,mysql无法启动

我有一个web服务器,默认安装 mysql将其所有数据库文件放在/ var / lib / MysqL中.安装/ var的分区只有2GB的空间,所以在运行空间问题后,我决定重新定位MysqL的数据目录.

我天真的方法是将/ var / lib / MysqL目录完全复制到/ web / dbs / MysqL,并更改/etc/MysqL/my.cnf以便它读取

datadir = /web/dbs/MysqL

但是,重新启动后,我在MysqL错误日志中收到以下错误,服务器将无法启动.

130130  9:59:23 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/MysqLd: Can't find file: './MysqL/plugin.frm' (errno: 13)
130130  9:59:23 [ERROR] Can't open the MysqL.plugin table. Please run MysqL_upgrade to create it.
130130  9:59:23  InnoDB: Initializing buffer pool,size = 8.0M
130130  9:59:23  InnoDB: Completed initialization of buffer pool
130130  9:59:23  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means MysqLd does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

所有文件和目录都属于MysqL:MysqL.为了测试,我甚至改变了/ web / dbs / MysqL的访问权限,现在是rwxrwxrwx.

是的,/ web / dbs / MysqL / MysqL / plugin.frm确实存在.

这可能是什么问题?我错过了什么吗?是否有更详细的输出日志?

更新:
更多信息:
我使用以下命令重试所有内容:

>我关闭服务器停止MysqL
>我删除了旧数据rm -r / web / dbs / MysqL
>我使用cp -p -r / var / lib / MysqL / / web / dbs /复制
>我将my.cnf中的datadir设置为datadir = / web / dbs / MysqL
>我重新启动了服务器.同样的错误

特权:

drwxr-xr-x  4 MysqL MysqL 34   2013-01-30 15:55 /web/dbs
drwx------ 19 MysqL MysqL 4096 2013-01-30 15:44 /web/dbs/MysqL
drwx------  2 MysqL MysqL 4096 2012-10-11 11:25 /web/dbs/MysqL/MysqL
-rw-rw----  1 MysqL MysqL 8586 2012-08-14 19:15 /web/dbs/MysqL/MysqL/plugin.frm

当我将datadir重置为datadir = / var / lib / MysqL时,服务器启动没有问题.

试过以下内容:

root:/# su - MysqL
MysqL:~$/usr/sbin/MysqLd --verbose
130130 16:01:05 [Warning] Can't create test file /web/dbs/MysqL/s15800994.lower-test
130130 16:01:05 [Warning] Can't create test file /web/dbs/MysqL/s15800994.lower-test

MysqL:~$touch /web/dbs/MysqL/s15800994.lower-test
MysqL:~$ls -l /web/dbs/MysqL/s15800994.lower-test
-rw-r--r-- 1 MysqL MysqL 0 2013-01-30 16:01 /web/dbs/MysqL/s15800994.lower-test

所以数据目录设置为correclty. MysqL用户具有写访问权限,但MysqL进程无法创建文件.

可能有什么不对?

解决方法

我们在评论中添加了解决方案作为完整性的完整答案……

使用su / sudo进行测试表明,虽然MysqLd抱怨权限错误,但MysqL用户确实可以成功写入该文件夹,明确表示这不是文件系统权限问题. (如遇到类似问题,这是有用的第一步)

Linux的一些发行版(如果不是全部?)现在附带AppArmor,它限制了允许可执行文件访问的文件/文件夹.

这种情况下的解决方案是简单地将新路径添加到/etc/apparmor.d/usr.sbin.MysqLd策略文件中.

linux 下mysql无法启动 mysql.sock

linux 下mysql无法启动 mysql.sock

在公司装的一键安装的lnmp环境,启动mysql时候发现mysql.sock不存在,

然后我进行查找  最后在  /usr/local/mysql/bin/mysql_safe  重新启动下  

 

然后启动service mysql start

  

查看 service mysql status

网上各种说法,其实还是自己的安装目录找到,然后去慢慢解决

这时候进入mysql又发现 密码错误  然后我试试初始密码 root 发现新问题

这个直接进入  /etc/my.cnf  进行编辑

再次重启mysql

然后这次就能进入了   输入mysql

 

update user set password=password("") where user="root";

然后在回到 刚才的 vim /etc/my.cnf  注释掉刚才添加的那句话    再次重启mysql  就ok完成了  

create database [dataname]  创建一个数据库

  show databases; 查看下     就可以进行数据库操作了

Linux下mSQL数据库设计技术_MySQL

Linux下mSQL数据库设计技术_MySQL

  mSQL(mini SQL)是一个单用户数据库管理系统,由于它的短小精悍,使其开发的应用系统特别受到互联网用户青睐。笔者曾经在Linux下开发过一个基于Web的管理系统,其中采用了mSQL数据库用于数据管理,系统在实际运行中效果良好。笔者经过总结,现将在Linux下mSQL数据库开发的方法详细介绍给大家。 

  首先,到站点www.hughes.com.au注册后就能免费下载该软件的最新版本。mSQL的安装相当简单,二进制版本(针对某一个硬件平台编译后的软件)的安装只是将文件展开到用户某一目录下然后配置几个参数就可以。例如你下载的文件为:mSQL-2.0.3.tar.gz,你想把mSQL安装到/usr/local目录下,这时,我们需要先将这个文件拷贝到/usr/local这个目录,然后键入命令tar zxvf mSQL-2.0.3.tar.gz,这个命令将展开该压缩文件。一般,mSQL数据库系统的所有文件都安装到/usr/local/Hughes目录下。接着就是配置mSQL数据库。你所要做的工作就是要修改/usr/local/Hughes目录下的文件msql.conf。

  在实际应用中我们改动得最多的是mSQL―User 和Admin―User这两个参数。mSQL―User指明运行mSQL数据库服务程序的用户,而Admin―User指明能对mSQL数据库系统执行特权操作(如:关闭数据库服务程序的运行,创建数据库等操作)的用户。因此,如果你希望mSQL服务程序以database这个用户运行,指定admin这个用户能执行数据库操作,你要将mSQL―User和Admin―User所在的行分别改为:mSQL―User = database和Admin―User = admin。另外你还必须将Hughes目录下的文件和目录的属主改为database。在配置完成后,注销当前用户的身份,重新以msql.conf的参数 mSQL―User设定的用户登录到系统,进入/usr/local/Hughes/bin目录键入如下的命令:./msql2d &,这样就启动了mSQL数据库系统。至于带源码的安装软件,看一看README和INSTALL这些文件一般就能顺利安装完成。

  为了将mSQL集成到用户的应用程序中去,mSQL数据库系统为用户提供了一个C语言的API库和一个解释器:w3―msql,通过C语言的API库,你可以将mSQL集成到用标准C语言开发的应用程序中去。而有了w3―msql这个工具,你可以通过编写类C语言脚本语言将mSQL数据库嵌入到HTML文件中,下面举一程序实例进行说明。

  下面的程序片段要完成的功能是将浏览器页面上提交上来的用户名和口令与表registered―user中的用户名和口令相比较,如果用户名和口令正确,将在页面上显示注册成功的信息,否则提示用户注册失败。采用C语言实现的方法如下所示:

  void main(int argc, char

Linux下MySQL 3数据库升级到MySQL 4.1乱码问题的完美解决

Linux下MySQL 3数据库升级到MySQL 4.1乱码问题的完美解决

这两天,研究了一下MySQL升级的乱码问题,终于解决了困扰我很久的问题,这里记录一下,以前相关的文章也已经更新了 以后就可以访问的

这两天,研究了一下MySQL升级的乱码问题,终于解决了困扰我很久的问题,这里记录一下,以前相关的文章也已经更新了

以后就可以访问的更换服务器了

先来看问题描述:

开始的服务器版本: Linux + Apache2.0 + php4.4.0 + mysql3.2.3 无乱码 (SQL导出文件起始地)
开始的本地测试版本: XP + IIS5.1 + php4.4.0 + mysql3.2.3 无乱码
更新的服务器版本: Linux + Apache2.0 + php4.4.0 + mysql4.1 无乱码 (空间提供商上传)
更新的本地测试版本: XP + IIS5.1 + php4.4.0 + mysql4.1 无乱码(不知道为什么,但是后来又乱码了)
最新的本地测试版本: XP + Apache2.0 + php4.4.0 + mysql4.1 乱码....崩溃..3天..未解决..

问题解决:

首先将 sql 文件从服务器上下载下来,或者从什么地方得到这个 sql 执行文件

1. 使用 UltraEdit 打开这个文件,观看文件是否是utf-8格式,下面的状态栏有提示,如果不是文件另存为UTF-8(无BOM)格式,观看文件的中文字符,是否显示正常,显示正常OK,继续

说明: 记着是 UltraEdit ,因为这个软件支持UTF-8编码文件(其他的也可以),windows自带的记事本可能出现匪夷所思的事情,无(BOM)格式也很重要,PHP不支持BOM头... 如果这里无法显示正常的话,不可能往下进行了...我试过,所以说多用不同形式导出几次,使得原始数据正常

2. 如果sql文件出现,新建表指令,注意中间的
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=101 ;
修改为: ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=101 ;

说明: 本操作就是告诉mysql表使用什么字符集

3. 新建数据库,使用 utf8_general_ci

4. 使用 phpMyAdmin 导入该文件到 mysql4, 导入的文件编码选择 UTF-8

说明: 如果导入错误,看看是否出现语法错误,修改,继续导入

5. 使用 phpMyAdmin 浏览相关记录,观看中文记录是否显示正常,正常继续

6. 浏览你的php程序,观看,读取数据库内容,仍然乱码,在打开数据库 @mysql_connect( $host, $user, $pass ) 类似语句之后添加 @mysql_query("SET NAMES ''utf8''");

7. 刷新网页,OK,成功

说明:

中间任何的过程出现错误,将导致转换失败

这里还有一个问题,就是现在所有的数据,前台数据,数据库数据,和传输过程的数据都用utf-8格式,所以相关的数据量必然会增大,如果网页特别巨大,而且考虑到页面加载问题,可能会出现一点问题
恩,相关的知识就不在这里细说了,我已经写在了这个博客中的"网站开发"类别中,想了解的,可以去看看

个人感觉.很复杂.mysql,phpmyadmin,php,mysql 各个方面都会导致乱码问题.

不过今天解决了 

linux

关于Linux下mysql数据库文件全部丢失mysql无法启动的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于linux – 重定位数据后,mysql无法启动、linux 下mysql无法启动 mysql.sock、Linux下mSQL数据库设计技术_MySQL、Linux下MySQL 3数据库升级到MySQL 4.1乱码问题的完美解决等相关知识的信息别忘了在本站进行查找喔。

本文标签: