Welcome to the website navigation,本站只接受合法正规的企业网站,欢迎站长们提交你的网站获得展示和流量有任何问题请联系站长,欢迎大家加入本站。

                
提交网站
  • 网站:76083
  • 待审:5
  • APP:577
  • 文章:304411
  • 会员:56004
文字内链包年1000元 文字内链包年1000元 文字内链包年1000元 AI办公网站 AI绘画工具 AIchat

Mysql中文乱码以及导出为sql数据库语句和Excel问题解决具体相关方法[图文]ycNAIChat_企业网址导航_网址分类目录_企业黄页网址提交查询专业网站!

先说明一下自己的环境:Mac OS X 10.8.3, MySQL Community Server 5.6.10, MySQL Workbench 5.2.47。,我想把本机网站数据库内的数据迁移到另一台机器上,于是使用Workbench中自带的import/export功能,其实就是调用mysqldump。不幸的是,出现了版本不一致的错误。, , , , , , , , ,错误没治了,最终找到解决方案,可以指定mysql的mysqldump,路径为:/usr/local/mysql/bin/mysqldump,这样是把数据导出为sql数据库语句的insert数据库语句。,由于需要是把数据导出为excel,所以通过mysql控制台使用select数据库语句把数据导出到excel网站网站文件中。,下面先介绍怎么导出为excel网站网站文件,然后介绍怎么导出为insert数据库语句。,1、通过终端操作办法。,1 cd /usr/local/mysql/bin/,2、到达bin目录后,可以ls -l开始执行命令看看当前目录有哪些程序可以用,这里先用mysql,开始执行命令格式为:,mysql -h主机IP -u用户名 -p密码,如:,1 ./mysql -hlocalhost -uroot -p123456,注意前面加的"./"。,这时就进入mysql开始执行命令控制台,终端上显示为:, , ,3、然后通过show databases开始执行命令查看当前的所有网站数据库,使用use开始执行命令选择进入某个网站数据库,注意每个开始执行命令都要以英文分号“;”结束。, , ,4、使用sql数据库语句导出需要的数据,sql数据库语句不限于单个表的查询。由于我的网站数据库编码是utf8格式,而office默认的编码则是gb2312,所以当某个字段中包含中文时,导出到excel后,中文内容是会, , ,我试着把网站网站文件保存到桌面,但始终提示没有权限,应该是和用户有关吧,无视了。当使用“./”这个路径保存时,实际是保存到了/usr/local/mysql/data下面。打开看看,哟西,不乱码了。,5、下面是把数据导出为sql的insert数据库语句。,使用mysqldump开始执行命令,可以指定是单个表还是整个网站数据库导出。,打开终端,定位到/usr/local/mysql/bin,使用这个目录下的mysqldump。,导出单个表:,开始执行命令格式为:,mysqldump -u用户名 -p密码 -h主机地址 网站数据库名 表名 > 导出网站网站文件存储路径,例如:,/usr/local/mysql/bin/mysqldump -uroot -p123456 -hlocalhost -t --extended-insert=false --default-char,其中用到了几个参数,简单说明一下:,-t:等同于--no-create-info,只导出数据,而不添加CREATE TABLE 数据库语句。默认导出的网站网站文件中也有create table数据库语句。,--extended-insert:使用具有多个VALUES列的INSERT语法,也就是传说中一次插入多条数据的INSERT句式。这样使导出网站网站文件更小,并加速导入时的速度,但是有可能sql数据库语句会有长度限,--default-character-set:设置默认字符集,由于我的网站数据库和表均是设定为utf8编码格式,当不设置此选项时,导出的中文是乱码,奇怪的是官方说明中,说这个选项的默认值是utf8,表示,导出整个网站数据库:,/usr/local/mysql/bin/mysqldump -uroot -p123456 -hlocalhost -t --extended-insert=false --default-char,二、导入数据。,有导出就有导入。上面第5步导出的sql网站网站文件,可以直接在mysql workbench中执行,也可以使用mysqldump导入,这里说明一下如何使用mysqldump导入:,/usr/local/mysql/bin/mysqldump -uroot -p123456 -hlocalhost --default-character-set=utf8 SpiderBBSDB ,三、关于java连接mysql写入中文乱码。,关于这个中文乱码问题,着实折腾了我好久好久。一开始就百度谷歌bing,网上大多复制粘贴的答案,在这里记录一下自己的情况,希望同路人不再走弯路。,其实我的修改很简单,把网站数据库的编码改为utf-8,在新建表时,把表的默认编码也改为utf-8,就可以了。就这么个小小的改动,让我足足折腾了一个通宵,表示有解决问题强迫症,问题不解决真的睡不着,唉~~~, , , , , , ,四、总结。,似乎很多领导做报告都喜欢加个总结,说上一堆废话,虽然回回都听不懂,但感觉很厉害的样子。于是我也加一个总结:中文乱码真特么折腾人,这些年跟您斗争了好多回了,好了,总结完毕。ycNAIChat_企业网址导航_网址分类目录_企业黄页网址提交查询专业网站!

当您安装 MySQL 完后、会有个提示:   [root@localhost Desktop]# rpm -ivh MySQL-server-5.5.28-1.rhel5.i386.rpm Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%]     PLEASE REMEMBER TO SET A PASSWORD FOR ThE MySQL root USER ! To do so, start the server, then issue the following commands:   /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'     Alternatively you can run: /usr/bin/mysql_secure_installation   **对于这 2 种相关方式、我个人认为、mysql_secure_installation 比较好用***   which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.     **我觉得、这里的关键应该是能够把匿名用户给删掉*** See the manual for more instructions.   Please report any problems with the /usr/bin/mysqlbug script!     By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for   them. This is intended only for testing, and to make the installationgo a bit smoother.   You should remove them before moving into a production environment   **匿名用户的危害****   所以、生产环境请务必删之!!     我选择 mysql_secure_installation     [root@localhost Desktop]# mysql_secure_installation   NOTE: RUNNING ALL PARTS OF ThIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACh STEP CAREFULLY!   In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here.   Enter current password for root (enter for none):  OK, successfully used password, moving on...     Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation.   You already have a root password set, so you can safely answer 'n'.   Change the root password? [Y/n] n ... skipping.   By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.   Remove anonymous users? [Y/n] y ... Success!   Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.   Disallow root login remotely? [Y/n] n ... skipping.   By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.   Remove test database and access to it? [Y/n] n ... skipping.     Reloading the privilege tables will ensure that all changes made so far will take effect immediately.     Reload privilege tables now? [Y/n] y ... Success!     Cleaning up...     All done! If you've completed all of the above steps, your MySQL installation should now be secure.   Thanks for using MySQL!

标签:

分享到:

  网友投稿

注册时间:

网站:0 个   APP:0 个  文章:0 篇

  • 76083

    网站

  • 577

    APP

  • 304411

    文章

  • 56004

    会员

赶快注册账号,推广您的网站吧!
文章分类
热门网站
最新入驻APP小程序

宝贝市场2023-02-08

宝贝市场——买手和卖家商品展示

夺宝助手2023-02-08

夺宝助手小程序,查看每日快夺宝平

查诚信2023-02-08

查诚信是一款免费的商业查询工具

车价天天报2023-02-08

快速连接汽车销售,获知汽车最新报

考勤助理小程序2023-02-08

上班签到考勤,实时定位,后台轻松

汽车报价大全查询2023-02-08

汽车报价大全查询提供最新汽车市