安装配置-MySQL/Redis

MySQL

安装

# Ubuntu
sudo apt update
sudo apt install -y mysql-server

配置

# set mysql
sudo mysql_secure_installation

"""
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.
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) : n                            # Press N
 ... skipping.
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                        # Press N
 ... 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) : n            # Press N
 ... skipping.
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                        # Press Y
Success.
All done! 
"""

# set bind-address and connect mysql
sudo sed -i 's/^bind-address.*/bind-address            = 0.0.0.0/'  /etc/mysql/mysql.conf.d/mysqld.cnf
sudo systemctl restart mysql.service
sudo mysql -uroot -p

### mysql cmd
# set root password 
use mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
UPDATE user SET host = '%' WHERE user = 'root';


# create database and user
CREATE DATABASE demo;
CREATE USER 'username' @'%' IDENTIFIED WITH mysql_native_password BY 'password123?';
GRANT ALL PRIVILEGES ON demo.* TO 'username'@'%' WITH GRANT OPTION;


# flush and quit mysql
flush privileges; 
quit;

Redis

安装

# Ubuntu
sudo apt update
sudo apt install -y redis-server

使用

import redis

# 连接本地 Redis 服务器,默认端口为 6379
r = redis.Redis(host='localhost', port=6379, db=0)

# 存储数据
r.set('mykey', 'Hello Redis!')

# 读取数据
value = r.get('mykey')
print(value.decode('utf-8'))  # 输出: Hello Redis!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值