我用如下命令安装了mysql:
brew install mysql
命令安装完mysql后,使用
mysql -u root -p
然后密码直接使用回车(空格)或者root都不行。
我百度了下,网上说用./mysqld_safe --skip-grant-tables &命令来跨过验证。
难道就没有办法能在某个配置文件中修改密码吗?或者有没有办法能自己设置密码呢?就像在window上安装mysql时可以自行设置密码一样。
题外话:为什么在终端中输入命令 mysql 会出现:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
麻烦大家解答下,不甚感激!!!
Through constant Baidu, Google and attempts, I finally solved it perfectly. I will record it now for the convenience of others later.
My system is Mac OS X 10.11, and I am going to install mysql 5.7.9.
Before you begin, it is assumed that your brew is already installed and ready to use.
Install mysql, enter the following command in the terminal and press Enter:
Wait for about 5 minutes (depending on the network speed). After the execution is completed, you will see this prompt:
You can see that brew has initialized mysql during installation (no need to execute the mysql_install_db command as mentioned on the Internet), and there is currently no password
So I followed its prompts and executed the command:
When a password is required, press Enter directly, and the following error occurs:
I did not see the mysql.sock file in the tmp directory.
I guess it will be created when the mysql service is started, so I executed the following command in advance:
Prompt .SUCCESS!
At this time, there is the file mysql.sock in the tmp directory, so I continue to execute mysql_secure_installation
OK! Done, you can use mysql -u root -p to connect with password
PS: I also tried randomly, and I don’t know if it is right, but at least it achieved what I wanted! ! !
mysql.server start
There are several possible questions:
First make sure the mysql service is started. You can use
ps au | grep mysql
to see if there is a mysql process. If not, you can use sudo mysqld_safe to start it.The mysql you just installed does not have a password. Just enter
mysql
directly on the command line to enter the mysql interactive mode.Set password:
mysqladmin -u root password "newpassword"
Or try another method, use a mysql GUI management tool to log in. Of course, you can also set a password through the GUI. This software is recommended for osx, or use the official mysql
Sequel Pro
mysqlbench
After typing the command, you still need to read the prompts
There will be a prompt after the installation command is executed
After the installation, you need to start MySQL mysql.server start
By default, there is no password after the installation, you need to set it yourself, refer to the answer upstairs
I didn’t have a password. I worked on it for a long time, but mariadb was still easy to use
Default no password:
This problem is driving me crazy
My system is ox el capitan
Brew reinstalled mysql
mysql.server start
Prompt
When executing mysql_secure_installation, an error message appears after entering the password and the process cannot be completed
为毛我的是
➜ ~ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
[1] 17759 segmentation fault mysql_secure_installation
Execute
There will be a prompt like this
To have launchd start mysql now and restart at login:
Or, if you don't want/need a background service you can just run: