sudo apt-get update
sudo apt-get install mysql-server mysql-client
sudo netstat -tap | grep mysql # 检查MySQL服务器是否正在运行
sudo /etc/init.d/mysql restart # 如果不能正常运行,手动重启
sudo service mysql restart # 重启服务
sudo apt-get install libapache2-mod-auth-mysql # 添加Apache对mysql支持
sudo apt-get install php5-mysql # 添加php对mysql支持
sudo apt-get autoremove --purge mysql-server-5.0
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> grant all PRIVILEGES on . to root@'%' identified by '19931128';
mysql> flush privileges;
netstat -anpt|grep 3306 # 检查3306端口
当前默认监听 127.0.0.1:3306
修改 127.0.0.1
为当前ip地址
修改 /etc/mysql/my.cnf
文件中 bind-address
,将 bind-address=127.0.0.1
修改为本机IP,重启mysql服务
/Applications/XAMPP/xamppfiles/xampp start
macos 使用了 Rootlees 对 /usr/bin 操作进行锁定
重启电脑,按住 command+r
,终端输入
csrutil disable
reboot
sudo chmod 777 /Applications/XAMPP/bin/mysql
ln -s /applications/xampp/bin/mysql /usr/bin
方法1:
格式:mysqladmin -u用户名 -p旧密码 password 新密码
注意:此处-p默认为空,可省略
方法2:
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
方法3:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass’);
修改MYSQL的配置文件:
my.ini
中修改 default-character-set=gbk
拷贝 /usr/local/mysql/support-files/my-medim.cnf
到 /etc
目录下
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
代码运行时修改: ① Java代码:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk ② PHP代码:header(“Content-Type:text/html;charset=gb2312”); ③ C语言代码:int mysql_set_character_set( MYSQL * mysql, char * csname);
shutdown -h now
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld start