[python] arch linux install mysql and use with python

1. 概述

Relational database like MariaDB is one of the required components to setup a web server as well as other less common uses such as when configuring a shared Kodi database. On Arch Linux MySQL has been replaced by a functionally identical community fork called MariaDB. The installation is also practically identical and as simple as can be expected.

2. 安装 MySQL / MariaDB

Install with pacman.

sudo pacman -S mariadb

Initialize data directories.

> sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

Two all-privilege accounts were created.

One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.

After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
Get Involved

By default MySQL will run as the user running the command unless a user is explicitly

specified with –user option. Path to the installation directory can be specified with –basedir option while data directory is specified with –datadir.

3. 运行 MySQL / MariaDB

Start the service with systemd & Enable the service to start on boot.

sudo systemctl start mysqld     #启动
sudo systemctl enable mysqld    #开机启动

Then reboot!

4. 配置 MySQL / MariaDB

Secure the installation.

sudo mysql_secure_installation

Make sure you set root password, remove anonymous users and disallow root login remotely unless you know you will need remote access to MariaDB. There should also be no need to keep test database so remove test database and access to it. Finish the install process with reload privilege tables now.

5. 使用 MySQL / MariaDB

Invoke the command line tool.

The username is specified with -u option follower by the username which is root by default. The password is specified with the -p option followed by the password without a space in between or the password can be omitted in which case MariaDB will prompt for one.

  • List all existing databases.
SHOW DATABASES;
  • List all database users.
SELECT DISTINCT User FROM mysql.user;

Use command line or Install phpMyAdmin to administer MySQL / MariaDB databases.

通过下面命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功:

sudo netstat -tap | grep mysql

登陆mysql数据库可以通过如下命令:

mysql -u root -p

-u 表示选择登陆的用户名, -p 表示登陆的用户密码,上面命令输入之后会提示输入密码,此时输入密码就可以登录到mysql。

下面是一些命令行中操作的DEMO,可做今后参考:

mysqladmin -u root -p create blog
mysql  mysql -u root -p
show databases;
use blog;

CREATE TABLE IF NOT EXISTS blog_table(
   blogId BIGINT UNSIGNED,
   url VARCHAR(100) NOT NULL,
   title VARCHAR(1000) NOT NULL,
   support INT UNSIGNED,
   pageView INT UNSIGNED,
   PRIMARY KEY ( blogId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS tag_table(
   tagId INT UNSIGNED AUTO_INCREMENT,
   tagName VARCHAR(100) NOT NULL,
   PRIMARY KEY ( tagId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS blog_tag_relation_table(
   relationId INT UNSIGNED AUTO_INCREMENT,
   blogId BIGINT UNSIGNED,
   tagId INT UNSIGNED,
   PRIMARY KEY ( relationId )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

show tables;
desc blog_table;
desc tag_table;
desc blog_tag_relation_table;

//change blogId int 2 bigint
alter table blog_table change blogId blogId BIGINT UNSIGNED;
//show data
select * from blog_table;
//delete data
delete from blog_table where blogId=201801021423;

INSERT INTO blog_table(blogId,url,title,support,pageView)
VALUES(201801021423,'http://106.14.226.191:3000/blog/201607281658.html','[商业_法务] 1、公司一款新消费类电子产品如何快速全面的专利保护',0,0);

//too short
alter table blog_table change title title VARCHAR(1000) NOT NULL;

INSERT INTO tag_table(tagId,tagName)
VALUES(0,'硬件_模拟电路');

select * from blog_table;
select * from tag_table;
select * from blog_tag_relation_table;

delete from blog_table where blogId>0;
delete from tag_table where tagId>=0;
delete from blog_tag_relation_table where relationId >= 0;

select a.title , a.url, b.tagName from blog_table a, tag_table b, blog_tag_relation_table c WHERE a.blogId = c.blogId AND a.blogId = 201602021408 AND b.tagId = c.tagId;

select a.title , a.url, b.tagName from blog_table a, tag_table b, blog_tag_relation_table c WHERE a.blogId = c.blogId AND b.tagId = c.tagId ORDER BY b.tagId;

为了python操作mysql需要执行下面命令:

pip install MySQL-python (arch linux 2.7 版本 python 会报错,建议用下面的命令)
sudo pacman -S mysql-python

链接

: 在 ubuntu 上比较好操作,在 arch linux 上有些难操作,这里记录下~

[python] arch linux install mysql and use with python

Original: https://www.cnblogs.com/zjutlitao/p/15357949.html
Author: beautifulzzzz
Title: [python] arch linux install mysql and use with python

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585661/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • [转帖]bash shell学习之变量

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年5月28日
    091
  • Vue3

    setup 函数时,它将接受两个参数:(props、context(包含attrs、slots、emit)) setup函数是处于 生命周期函数 beforeCreate 和 Cr…

    Linux 2023年6月13日
    085
  • Linux专项之Apache

    1.虚拟机上网 1.安装软件(httpd) yum search ht…

    Linux 2023年5月27日
    094
  • MySQL事务隔离级别

    MySQL事务隔离级别 事务 事务是由单独的一个或者多个SQL语句组成,是一个最小的不可再分割的单元,这一组操作里面的所有的执行,要么全部成功、要么全部不成功。如果有一个执行不成功…

    Linux 2023年6月6日
    0119
  • 20191223-Exp3-免杀原理

    Exp3-免杀原理 姓名:张俊怡 学号:20191223 课程:网络对抗技术 一、实践内容 方法 正确使用msf编码器,使用msfvenom生成如jar之类的其他文件 veil,加…

    Linux 2023年6月8日
    0127
  • std::map自定义类型key

    故事背景:最近的需求需要把一个结构体struct作为map的key,时间time作为value,定义:std::map 技术调研:众所周知,map是STL库中常用的关联式容器,底层…

    Linux 2023年6月13日
    0125
  • Linux系统Yum中的$releasever和$basearch变量

    Yum的配置文件中包含大量的$releasever和$basearch变量,那么他们的取值是什么呢? 为什么要折腾这个玩意呢?有点地方的网络是私有化网络,内部有大量的Linux服务…

    Linux 2023年6月8日
    087
  • 技术漫谈之——Jectpack Compose

    最近Jetpack Compose发布了Beta版本,抽时间了解了一下Compose带来的改变和其中的一些原理。本文不会讲解具体API,只是比较随意的分享自己的一些疑问以及在探寻答…

    Linux 2023年6月13日
    096
  • Linux内核中内存管理相关的数据结构

    本文简要说明几个内核和内存管理有关的结构体。其中 struct page 和 struct zone有较大幅度的删减,主要删减了和NUMA模型SPARSE模型以及内存热插拔相关的域…

    Linux 2023年6月7日
    0107
  • Redis集群原理及搭建(Twemproxy、Predixy代理搭建、Redis Cluster集群)

    1 引言 网上很多文章会把集群和主从复制混为一谈,其实这两者是存在本质差异的,各自解决的问题不同。Redis在单机/单节点/单实例存在的风险: 单点故障、 容量有限、 并发压力问题…

    Linux 2023年6月13日
    099
  • Redis

    Redis原创笑笑师弟 最后发布于2018-12-21 14:17:59 阅读数 1780 收藏展开目录 redis简介 redis功能 redis学习步骤 windows系统下的…

    Linux 2023年5月28日
    0103
  • muduo项目介绍

    在上一个集群聊天服务器项目中,我使用了 muduo作为网络库,然后主要实现了业务逻辑等,所以为了深入网络库的代码和实现,我跟着一位老师的代码去实现了 muduo库的基本原理和作用,…

    Linux 2023年6月13日
    0106
  • 世界上最流行的操作系统不是Windows?

    前言 打住,我知道列位是被标题骗进来的,但是这个论题并不是我瞎吹牛,世界上最流行的操作系统还真不是Windows。 提及操作系统,我们印象中比较深刻的无非就是Windows,Lin…

    Linux 2023年6月13日
    0114
  • python 练习题:使用迭代查找一个list中最小和最大值,并返回一个tuple

    python;gutter:true; -<em>- coding: utf-8 -</em>-</p> <p>请使用迭代查找一个l…

    Linux 2023年6月8日
    090
  • Shell实现:基本功能

    独立博客阅读地址:https://panqiincs.me/2017/02/26/write-a-shell-basic-functionality/ Shell的功能 Shell…

    Linux 2023年6月7日
    0132
  • 超算TOP500中的Linux占比——Operating System&Operating System Family

    2022-09-18-21:28:59 老师作业说明: TOP500中国超算占比,LINUX系统占比 说明:当时使用的是bing搜索,中国超算占比其实澎湃新闻什么的都有介绍,但是我…

    Linux 2023年6月6日
    099
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球