mysql是非常常用的关系型数据库,在安装过程中时常有坑,特别是我经常重装系统,囧。
环境:
ubuntu18.04.3
##安装mysql5.7.28
sudo apt install mysql-client mysql-server
##登录mysql
sudo mysql -uroot -p
Enter password:
修改密码
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "yourpassword";
Query OK, 0 rows affected, 1 warning (0.00 sec)
##新建database
mysql> CREATE DATABASE andrew;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON weixx.* TO mac@"%" IDENTIFIED BY "python";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit;
Bye
遇到的坑:
macos10.15
mariadb
mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
按照教程,可能是service未开启。
开启mysql service
mysql.server start
Starting MariaDB
.191201 18:02:08 mysqld_safe Logging to '/usr/local/var/mysql/macbook.err'.
191201 18:02:08 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
/usr/local/bin/mysql.server: line 264: kill: (57974) - No such process
ERROR!
重新安装mysql
brew install mysql
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
error: could not lock config file .git/config: Permission denied
Error: Cannot install mysql because conflicting formulae are installed.
mariadb: because mysql, mariadb, and percona install the same binaries.
Please `brew unlink mariadb` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side effects in the
resulting software.
已经安装了mariadb
brew unlink mariadb
brew install mysql
安装成功!!!!
然后登录的时候,一样报错,然后重启服务,可以登录,不是系统密码。
mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
andrew@1macbook:~#mysql.server start
Starting MySQL
.. SUCCESS!
andrew@macbook:~#mysql -uroot -p
直接enter进去,
按照上面的方式修改密码,一直报错,
要这样
ALTER USER "root"@"localhost" IDENTIFIED BY "大小写复杂的密码";