弄这东西用了两天,坑爹啊,不过终于弄好了,还有发现的一些不错的,一块分享给大家,以免以后有人再像我这样浪费时间
一:
删除 MysqL sudo apt-get autoremove --purge MysqL-server-5.7(注意这里是自己之前安装的MysqL的对应版本) sudo apt-get remove MysqL-server sudo apt-get autoremove MysqL-server sudo apt-get remove MysqL-common //这个很重要 清理残留数据 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
二:
安装MysqL
1.安装
sudo apt-get install MysqL-server(此处会提示设置密码) sudo apt-get install MysqL-client sudo apt-get install libMysqLclient-dev
如果中途有问题就执行以下 apt-get update
2.检查是否安装成功
sudo netstat -tap | grep MysqL
(注意,本机没有设置远程连接,如果需要的话自行百度一下)
到此,数据库已经安装好了
先登录数据库,然后输入show variables like 'character_set%';
查看此时的编码格式
接下来要修改两个位置
1.修改/etc/MysqL/MysqL.conf.d/my-default.cnf
wuxiushu@root:~$ sudo su root@root:/home/wuxiushu# cd /etc/MysqL root@root:/etc/MysqL# ls conf.d debian-start my.cnf.fallback MysqL.conf.d debian.cnf my.cnf MysqL.cnf root@root:/etc/MysqL# cd MysqL.conf.d root@root:/etc/MysqL/MysqL.conf.d# ls MysqLd.cnf MysqLd_safe_syslog.cnf root@root:/etc/MysqL/MysqL.conf.d# gedit MysqLd.cnf
[MysqLd] # # * Basic Settings # user = MysqL pid-file = /var/run/MysqLd/MysqLd.pid socket = /var/run/MysqLd/MysqLd.sock port = 3306 basedir = /usr datadir = /var/lib/MysqL tmpdir = /tmp lc-messages-dir = /usr/share/MysqL skip-external-locking 此位置下面添加下面三句 default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci
保存退出
2.修改/usr/share/MysqL/my-default.cnf
wuxiushu@root:~$ sudo su root@root:/home/wuxiushu# cd /usr/share/MysqL root@root:/usr/share/MysqL# ls bulgarian magic charsets my-default.cnf czech MysqLd_multi.server danish MysqL-log-rotate debian_create_root_user.sql MysqL_security_commands.sql dictionary.txt MysqL_sys_schema.sql docs MysqL-systemd-start dutch MysqL_system_tables_data.sql echo_stderr MysqL_system_tables.sql english MysqL_test_data_timezone.sql errmsg-utf8.txt norwegian estonian norwegian-ny fill_help_tables.sql polish french portuguese german romanian greek russian hungarian serbian innodb_memcached_config.sql slovak install_rewriter.sql spanish italian swedish japanese ukrainian korean uninstall_rewriter.sql root@root:/usr/share/MysqL# gedit my-default.cnf
[MysqLd] port = 3306 socket = /var/lib/MysqL/MysqL.sock character-set-server=utf8
3.重启MysqL
sudo service MysqL restart
启动MysqL
MysqL -u root -p
之后再次输入show variables like 'character_set%';
运行结果如下
MysqL> show variables like 'character_set%'; +--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)原文链接:https://www.f2er.com/ubuntu/356470.html