为了方便启动mysql服务,修改/etc/.bash_profile文件,如下
alias mysql="/usr/local/mysql/bin/mysql"
alias mysqladmin="/usr/local/mysql/bin/mysqladmin"
或者
alias mysqlstart="sudo /usr/local/mysql/support-files/mysql.server start"
alias mysqlstop="sudo /usr/local/mysql/support-files/mysql.server stop"
由于想启动mysql,然后修改root密码而出现以下问题:
问题1:
ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysqld.local.pid).
解决方案:
在/etc目录下创建my.cnf(touch /etc/my.cnf),或者直接在/usr/local/mysql/support-files/my-default.cnf中添加,内容如下:
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysqld.local.pid
user = mysql
tmpdir = /tmp
问题2:
ERROR2002(HY000):Can't connect to local MySQL server through socket '/tmp/mysql.sock'(2)
在/etc目录下创建my.cnf(touch /etc/my.cnf),或者直接在/usr/local/mysql/support-files/my-default.cnf中添加,内容如下:
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect ='SET NAMES utf8'
max_allowed_packet = 64M
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
innodb_file_per_table=1
#已添加内容
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysqld.local.pid
user = mysql
tmpdir = /tmp
[mysqld_safe]
timezone = '+0:00'
问题3:
重设root密码步骤:
步骤1:sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables(跳过密码)
步骤2:sudo mysql -u root(不使用密码登录,由于之前alais了,所以可以直接写mysql,不然需要写全路径sudo /usr/local/mysql/bin/mysql -u root)
步骤3:已登入mysql,修改用户密码
UPDATE mysql.user SET authentication_string=PASSWORD('新密码') WHERE User=‘root’;
FLUSH PRIVILEGES;
但是在第一个步骤时,报错:mysql_safe A mysqld process already exists
查看是否有正在运行的mysql进程:ps -ef|grep mysql
kill -9 pid杀死进程后,mysql自动启动。
原因:实质应该是有守护进程listen,若kill掉马上又启动一个
解决:试过答案中mysqlstop,但是没有作用!
打开设置,选择mysql
然后不勾选自动启动,输入用户密码
然后重启电脑。
然后再按照重设密码步骤,修改密码成功。