Ubantu环境下安装mysql方法

一、Ubantu镜像源更改:

1、切换root用户sudo passwd root 密码

2、修改/etc/apt/sources.list,删掉所有,改为阿里镜像

https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11Tm9mlf

(Python镜像源:pip install *** -i https://pypi.doubanio.com/simple 或 https://pypi.tuna.tsinghua.edu.cn/simple)

3、root用户下或sudo apt update更新镜像源

二、安装mysql

apt install mysql-server mysql-client,安装成功也没有提示输入用户名密码,mysql默认密码为空,可直接进去

但是使用mysql -uroot -p 命令连接mysql时,报错

修改方法:

1.进入到etc/mysql 目录下,查看debian.cnf文件

2、使用配置的用户名密码登录

登录:mysql -udebian-sys-maint -pxedvSNKdLavjuEWV

3、修改密码

show databases;
use mysql;
update user set authentication_string=PASSWORD("自定义密码") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit;

4.修改完密码,需要重启mysql

/etc/init.d/mysql restart;

5.再次登录
mysql -u root -p 密码;OK!

三、卸载

sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
#检查mysql是不是在运行
sudo service mysql status
sudo service mysql start

四、 其他:

开发机运行正常,git到Ubantu上执行python manage.py db migrate后,报错

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1698, "Access denied for user 'root'@'localhost'")

参考:https://www.cnblogs.com/TheInvoker/p/9869771.html

执行python manage.py db migrate报错版本不统一,除了删migrations文件夹,还有这个:

$ python manager.py db stamp head

$ python manager.py db migrate

$ python manager.py db upgrade

 

原文地址:https://www.cnblogs.com/iamorz/p/12883266.html