linux下装mysql

来源:互联网 发布:淘宝信用借贷额度 编辑:程序博客网 时间:2024/06/05 07:50

之前参考锅网上帖子的很多,因为没有从一而终,我遇到各种错误。珍惜生命,删繁就简。

可以参考中文官方文档,操作简单可靠。链接:http://wiki.ubuntu.org.cn/index.php?title=MySQL%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97&variant=zh-cn

按照上述链接,可做到登录正常.『之后可以自行查询如何更改密码或进一步配置mysql各项参数』



今天重启电脑登录遇到一个问题:

            root@allenli-U80V:~# mysql -uroot  -p
            Enter password:
            ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

 

在查看此链接之后:http://www.linuxsir.org/bbs/thread214347.html    

原因在于之前没有启动mysql,所以登录失败。

下面这样就问题了:

root@allenli-U80V:~# service mysql start            //启动mysql后才可登录
Starting MySQL
 *
root@allenli-U80V:~# mysql -u root -p                                .//登录成功
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>






mysql中文乱码导论



















网上类似帖子太多,具体操作也记不清的。以自身经历看。
乱码的原因在于你是用什么编码方式对它进行读写的?在网页上显示的时候,网页本身也有自己的编码方式。这一系列的编码方式(utf8,gbk,latin等)如果前后不一致,乱码就会乱得你一塌糊涂,以至于你判断字符是否相等的时候:s.xm='刘晓明'就会出错.


我们说,如果发生乱码,可以
【1】   导出数据库再重建一个数据库再导进去,这点我表示没试过。
                    http://blog.chinaunix.net/uid-25266990-id-3344584.html

【2】
  • 查看状态:mysql> show variables like "%char%"; 并将数据编码格式保存为utf-8
  • 设置默认编码为utf8:set names utf8;
  • 设置数据库db_name默认为utf8:   ALTER DATABASE `db_name` DEFAULT CHARACTER                      SET utf8 COLLATE utf8_general_ci;
  • 设置表tb_name默认编码为utf8:   ALTER TABLE `tb_name` DEFAULT CHARACTER SET                  utf8 COLLATE utf8_general_ci;
  • http://www.2cto.com/database/201108/101151.html
-------------------------------------------------------------------------------
 我们说,防微杜渐才好,下次记得一开始就要统一编码格式,像这样.

一、create database db_name default charset=utf8;
    creaete table tb_name(...)default charset=utf8;
这样在mysql控制台下会看到正常字符

二、mysql load infile数据缺损或者乱码
load data infile '/wamp/www/mydata/t.txt' into table t
 character set gbk   /*这行可以解决字符导入缺损\乱码问题*/
fields terminated by '\t'
       enclosed   by '\"'
lines  terminated by '\r\n'
ignore 1 lines;

// character set utf8造成导入字符缺损或者乱码:一堆问号
通过character set gbk可以使得导入操作成功。

三、网页乱码解决
在网页代码中加入语句:
mysqli->query("set names gbk")






         

        


0 0