ubuntu 下使用mysql
第一步:安装mysql
apt-get install mysql-server
第二步:设置允许远程登录
修改/etc/mysql/my.cnf(此文件为mysql的配置文件)。将文件中的binding-address=127.0.0.1注释掉。
从本机登陆mysql:mysql -u root -p
use mysql;
设置允许所有主机连接到Mysql,执行命令:grant all privileges on *.* to root@"%" identified by "root用户的密码" with grant option;
第三步:
重启mysql
/etc/init.d/mysql restart
*注:/etc/init.d/mysql start|stop|restart可以启动/停止/重启
第四步:设置开机自启动
把启动命令(/etc/init.d/mysql start)加入/etc/rc.local文件中
第五步:设置Mysql字符集:
创建数据库时指定字符集:create database mydb character set utf-8;
查看当前字符集:show variables like 'character%';
修改当前数据库的字符集:
mysql> SET character_set_client = utf8 ;
mysql> SET character_set_connection = utf8 ;
mysql> SET character_set_database = utf8 ;
mysql> SET character_set_results = utf8 ;
mysql> SET character_set_server = utf8 ;
mysql> SET NAMES utf8; //这条语句会改变 character_set_client character_connection character_results这三个 的字符集
END
注意事项
/etc/init.d/mysql start|stop|restart可以启动/停止/重启
-bash: mysql: command not found
用mysql命令进行登陆mysql报错,原因是没有设置环境变量,需要设置,或者进入到bin目录进行登陆cd /usr/local/mysql/bin
mysql -u root