ubuntu安装mysql遇到ROOT不能访问的问题

使用ubuntu12.04安装mysql:sudo apt-get install mysql-server

然后使用命令mysql -u root -proot报出错误: 'Access denied for user 'root'@'localhost' (using password: YES)'

最开始的解决办法是使用了 http://www.cnblogs.com/songmingming/p/3150469.html里面的办法。

今天重新在另外的机器上安装,在安装过程中需要输入密码和确认密码,想起WINDDOW的安装模式下,就输入了root作为密码,安装完成以后,可以使用mysql登录和mysql -u root -proot登录,我觉得实际上是安装的问题,这样的问题的WINDOW上类似出现


安装mysql修改字符集 /etc/mysql/my.cnf

[client]
....
default-character-set=utf8


[mysqld]
.....
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'


然后sudo start mysql即可

在阿里云上面虽然这样设置,但是character_set_database依然不是utf8, 后来把[client]下面的设置删除,然后只保留[mysqld]的就可以,网上说5.5的版本字符集设置的问题。我用的是5.5.35就可以,阿里云上面是5.5.34就不行,抓狂。。。。。


最后的排查:
先登录mysql -u root -proot

检查字符集
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

所有都是对的

然后选择某一个数据库use test;
在检查字符集
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latinl                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

说明是某一个数据问题,单独设置:
alter database test character set utf8;
然后再检查,一切OK。


使用sql导入数据,由于最开始我没有初始化表,而直接采用jpa注入的形式,
mysql> show table status from test like 'master_config';
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
| Name             | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation         | Checksum | Create_options | Comment |
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+
| master_config | InnoDB |      10 | Compact    |   27 |            606 |       16384 |               0 |            0 | 103809024 |             55 | 2014-01-27 12:40:03 | NULL        | NULL       | latin1_swedish_ci |     NULL |                |         |
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+---------+

所以最好用sql建表

你可能感兴趣的:(mysql,ubuntu)