MySQL database_MAC system to install MySQL

MySQL database

MySQL installation, startup and shutdown

Because I use mac , the installation steps here are only applicable to mac ; under
mac system, there are two ways to install, one is through the installation package, the other is through the command line.

Reference article: http://www.jianshu.com/p/fd3aae701db9

Here I chose to install it through Homebrew's command line. The specific operations are as follows:

brew install mysql

mysql01

mysql02

After the installation is complete, the 启动mysql服务following error is encountered

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Execute the following commands in sequence

sudo chown -R 'xxxxx' /usr/local  # 这里的‘xxxxx’是电脑的用户名
brew link --overwrite mysql
unset TMPDIR
bash mysql_install_db --verbose --user=root
--basedir="$(brew --prefix mysql)"--datadir=/usr/local/var/mysql --tmpdir=/tmp

Next we start the mysqlservice

Start/stop mysql service

brew services start mysql  /  brew services stop mysql

mysql.server start  /  mysql.server stop

bash mysql.server start  /  bash mysql.server stop

mysql03

Verify login

When the mysql service is started, according to the prompt during the installation process, we enter mysql -uroot

When there is mysql >time, that means, we successfully installed

carried out select database();

mysql04

Configure a new password

  • Enter the mysql command status: (mysql> is the mysql command status prompt)

Update root password

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

Please use the following SQL for the latest version of MySQL:

mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';

Refresh permissions

mysql> FLUSH PRIVILEGES;

Exit mysql

mysql> quit

Restart mysql

/mysql服务路径执行重启命令 $ mysqld restart

Log in to mysql again as the root user

mysql -uroot -p 
Enter password: <输入新设的密码newpassword>

Guess you like

Origin blog.csdn.net/weixin_42250835/article/details/90214241