当前位置:   article > 正文

Ubuntu下MySQL的安装、配置、启动、停止、重启、乱码问题_ubuntu 改完mysql配置需要重启么

ubuntu 改完mysql配置需要重启么
Ubuntu下

安装MySql及Php5

sudo apt-get install mysql-server
sudo apt-get install mysql-client

sudo apt-get install php5-mysql


启动、停止、重启mysql 服务

 启动mysql:
方式一:sudo /etc/init.d/mysql start
方式二:sudo start mysql
方式三:sudo service mysql start

停止mysql:
方式一:sudo /etc/init.d/mysql stop
方式二:sudo stop mysql
方式三:sudo service mysql stop

重启mysql:
方式一:sudo/etc/init.d/mysql restart
方式二:sudo restart mysql
方式三:sudo service mysql restart

设置MySQL编码


【使用apt-get 命令安装的mysql默认不是utf8、在这里记录一下如何将编码修改成utf8】
一:查看mysql版本
1.1 mysql –V
在终端界面输入上面命令、显示如下:
                mysql  Ver 14.14 Distrib 5.5.35, fordebian-linux-gnu (x86_64) using readline 6.2

1.2 status
a) 登录mysql
                mysql –uroot –ppassword

b) 输入如下命令:
                status
                #会有如下显示:
                --------------
                mysql  Ver 14.14 Distrib5.5.35, for debian-linux-gnu (x86_64) using readline 6.2
 
                Connection id:          45
                Current database:
                Current user:           root@localhost
                SSL:                    Not inuse
                Current pager:          stdout
                Using outfile:          ''
                Using delimiter:        ;
                Server version:        5.5.35-0ubuntu0.12.04.2 (Ubuntu)
                Protocol version:       10
                Connection:            Localhost via UNIX socket
                Server characterset:    latin1
                Db     characterset:    latin1
                Client characterset:    utf8
                Conn.  characterset:    utf8
                UNIX socket:           /var/run/mysqld/mysqld.sock
                Uptime:                 1 hour15 min 13 sec
 
                Threads: 1  Questions:609  Slow queries: 0  Opens: 421 Flush tables: 1  Open tables:41  Queries per second avg: 0.134
                --------------

1.3 selectversion();
a) 登录mysql
                mysql –uroot –ppassword

b) 输入如下命令:
                select version();
                #会有如下显示:
                +-------------------------+
                | version()               |
                +-------------------------+
                | 5.5.35-0ubuntu0.12.04.2 |
                +-------------------------+
                1 row in set (0.00 sec)

二:查看mysql编码
                show variables like '%character%';
                #会有如下显示:
                +--------------------------+----------------------------+
                | Variable_name            | Value                      |
                +--------------------------+----------------------------+
                | character_set_client     | utf8                       |
                | character_set_connection | utf8                       |
                |character_set_database   | latin1                     |
                | character_set_filesystem | binary                     |
                | character_set_results    | utf8                       |
                |character_set_server     | latin1                     |
                | character_set_system     | utf8                       |
                | character_sets_dir       | /usr/share/mysql/charsets/ |
                +--------------------------+----------------------------+
                8 rows in set (0.00 sec)

三:修改mysql编码
上面步骤中可以看出编码——latin1

3.1 修改mysql的配置文件——/etc/mysql/my.cnf:
a) 打开mysql配置文件:
                vim /etc/mysql/my.cnf

b) 在[client]下追加:
                default-character-set=utf8

c) 在[mysqld]下追加:
                character-set-server=utf8

d) 在[mysql]下追加:
                default-character-set=utf8

e) 保存并退出

:w !sudo tee %  vim中权限不足时不用退出而强制保存

:q!      vim 强制退出,不保存更改内容


3.2 重启mysql服务, 查看mysql编码是否修改成功, 登录mysql 输入:
                show variables like '%character%';
                #会有如下显示:
                +--------------------------+----------------------------+
                | 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/ |
                +--------------------------+----------------------------+

则修改成功!



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/187900
推荐阅读
相关标签
  

闽ICP备14008679号