数据库—2(ubuntu 18.04 安装 mysql)

1. 检查有没有安装mysql 数据库

#dpkg -l | grep mysql
#apt install mysql-server

#如果安装 先根据版本进行卸载 我的就版本是5.7
apt-get autoremove --purge mysql-server-5.7

2. 检查mysql是否安装成功,安装成功后处于监听状态

  #netstat -tap | grep mysql

3. 对数据库进行初始化操作,便于数据库能正常安全运行


# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N   # 我选择N
Please set the password for root here.

New password: 

Re-enter new password: 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   # 删除匿名账户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N # 是否禁止root远程登录

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 删除test数据库并取消对它的访问权限
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 刷新授权表,让初始化后的设定立即生效
Success.

All done! 

4. 配置mysql允许远程访问, /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

   注释掉bind-address          = 127.0.0.1

5. 进入mysql数据库,执行授权命令:

#mysql -u root -p

#root用户能任意主机访问所有的数据库, '你的密码‘为# mysql_secure_installation 配置的root密码

mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;        

#只允许root用户本地访问所有的数据库

mysql> grant all on *.* to root@localhost identified by '你的密码' with grant option; 

mysql>CREATE DATABASE kaitest;

#kaikai用户可以从任意机器上登入mysql的kaitest数据库 ,以密码654321

mysql> GRANT ALL PRIVILEGES ON kaitest.* TO kaikai@"%" IDENTIFIED BY "654321" WITH GRANT OPTION;

#允许myuser 用户在192.168.1.76 主机上 以 mypassword 访问任意数据库

mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.76' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

mysql> flush privileges;    # 刷新权限

mysql> exit

 

6.重启数据库

#systemctl restart mysql     #重启数据库

 

远程查看数据库

下载nvicat For MySQL 数据库查看工具

 

可以看到root用户能够访问到的数据库

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值