1.本地连接数据库
[root@iZ253lxv4i0Z mysql]# mysql -u root -p
Enter password:or:
[root@iZ253lxv4i0Z mysql]# mysql -u root -p mysql
Enter password:2.查看端口
mysql> show global variables like 'port'
-> ;+---------------+-------+| Variable_name | Value |+---------------+-------+| port | 3306 |+---------------+-------+3.查看数据库
mysql> show databases;
+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test || wordpress_db |+--------------------+4.show variables like 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |+----------------------+-------------------+| collation_connection | utf8_general_ci || collation_database | latin1_swedish_ci || collation_server | latin1_swedish_ci |+----------------------+-------------------+5.show variables like 'character_set_%';
+--------------------------+----------------------------------------------+
| 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 | /alidata/server/mysql-5.6.15/share/charsets/ |+--------------------------+----------------------------------------------+6.alter database mydb character set utf-8;
ERROR 1115 (42000): Unknown character set: 'utf'
7.alter database mydb character set utf8;
ERROR 1 (HY000): Can't create/write to file './mydb/db.opt' (Errcode: 2 - No such file or directory)
8.quit;
退出
9.通过配置文件修改:
修改/var/lib/mysql/mydb/db.opt(进入mysql根目录,找到data目录并cd进入,再找到你要修改的数据库的目录并进入,进去之后就可以看到db.opt)
default-character-set=latin1 default-collation=latin1_swedish_ci 为 default-character-set=utf8 default-collation=utf8_general_ci10.重启MySQL(进入Server目录)
service mysqld restart
11.启动/停止MySQL(进入Server目录)
service mysqld start
service mysqld stop
12.