Mysql重新安装(ubuntu)
1、dpkg -l,查找出linux上安装的mysql相关的服务,比如我的有mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5这些
2、卸载:sudo apt-get --purge remove mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5
3、手工删除mysql在服务器上的表文件和配置文件
4、安装:sudo apt-get install mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5
在安装过程中要输入root密码,这样就安装成功了。
重要的在后面:
平时不要使用root账号连接mysql服务,同时尽量不要让其他任何客户端都能链接到你的mysql服务(就是那个host不要设为%)。否则后果很严重。下面是创建普通用户及授权的操作:
CREATE USER 'username'@'host' IDENTIFIED BY 'pwd';
GRANT ALL ON dbname.* TO 'username'@'host';
flush privileges;
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
flush privileges;
设置mysql默认编码方式:(/etc/mysql/my.cnf)
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default_character_set=utf8(此处为添加部分)
[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
character-set-server=utf8(此处为添加部分)
init_connect='SET NAMES utf8'(此处为添加部分)
然后重启mysql。
/etc/init.d/mysql restart