CentOS7 MySQL

CentOS 7 安装MySQL服务:

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
sudo yum install mysql-server

启动MySQL服务:

sudo systemctl start mysqld
sudo systemctl status mysqld

启动时的临时密码:

sudo grep 'temporary password' /var/log/mysqld.log

 

修改密码:

MySQL 5.7.6及以上版本:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5及以下版本:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

 

忘记密码后重置密码:

1.修改MySQL的登录设置:

    # vim  /etc/my.cnf 

    在[mysqld]的段中加上一句:skip-grant-tables 

    例如:

    [mysqld] 

    datadir=/var/lib/mysql 

    socket=/var/lib/mysql/mysql.sock 

    skip-grant-tables 

    保存并且退出

2、重新启动mysql

    service mysql restart

3、登录并修改登录密码

    #mysql

    #use mysql

    update user set Password=password('密码') where  user='root' ;

    quit;

4、强配置改回来

   去掉 skip-grant-tables 

5、重新启动mysql

    service mysql restart

 

 

CentOS 7 Python安装MySQLdb模块:

sudo yum install mysql mysql-devel mysql-lib
sudo yum install MySQL-python
pip install mysql-python

 

参考:

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7

https://stackoverflow.com/questions/4380931/installing-mysql-python-on-centos

https://my.oschina.net/u/2297737/blog/688214

posted @ 2018-04-19 13:11  ijustwanttorun  阅读(189)  评论(0编辑  收藏  举报