MySQL installation and use under linux (ARM) architecture (full version)

Table of contents

1. Change the source before installing MYSQL

2. Install MYSQL

1. Installation

2. The installation is complete

3. Unable to log in after installation

3.1 Reasons

3.2 Switch database after login

3.3 Change the password (note that the account number and password are in double quotes)

3.4 Check the user

3.5 Then refresh to make the configuration take effect

3.6 Exit

3.7 restart

Three, mysql use test


1. Change the source before installing MYSQL

1. Back up the previous source of the system, or not, comment out the previous source

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2. Modify the source file /etc/apt/sources.list

vim /etc/apt/sources.list

Delete the original content and paste the source content below.

3. Here are two good domestic sources recommended

3.1 Ali source (arm64, fast, recommended)

deb http://mirrors.aliyun.com/ubuntu-ports/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial main
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial universe
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe
 
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe

3.2 Huawei source (arm64, fast speed, choose one of the two)

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
 
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
 
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
 
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
 
## Not recommended
# deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse

4. Update warehouse

apt-get update

4.1 Handling Error Reporting

There may be an error

The following signatures cannot be verified because the public key is not available...

The following command solves it:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 40976EAF437D05B5 3B4FE6ACC0B21F32

5. Clear software repository cache

apt-get clean

6. Update software repository

apt-get update

Done, you can install MYSQL

2. Install MYSQL

1. Installation

sudo apt-get install mysql-server          //服务端
sudo apt-get install mysql-client          //客户端
sudo apt-get install libmysqlclient-dev    //程序编译时链接的库

2. The installation is complete

After the installation is complete, the dpkg command checks the status

dpkg -l | grep mysql

If the following information is output, the installation is successful

ii  mysql-client-5.7                              5.7.39-0ubuntu0.18.04.2         arm64        MySQL database client binaries
ii  mysql-client-core-5.7                         5.7.39-0ubuntu0.18.04.2         arm64        MySQL database core client binaries
ii  mysql-common                                  5.8+1.0.5                       all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                                  5.7.39-0ubuntu0.18.04.2         all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7                              5.7.39-0ubuntu0.18.04.2         arm64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7                         5.7.39-0ubuntu0.18.04.2         arm64        MySQL database server binaries

Start mysql with the following command

service mysql start

After startup, use the following command to view the status

sudo netstat -anp | grep mysql

The following display shows that the startup is successful:

tcp6       0      0 :::3306                 :::*                    LISTEN      27608/mysqld        
unix  2      [ ACC ]     STREAM     LISTENING     648125   27608/mysqld         /var/run/mysqld/mysqld.sock
unix  3      [ ]         STREAM     CONNECTED     648111   27608/mysqld    

Log in with the command

mysql -u root -p

Enter the password to log in. If you have not set a password before, please see step 3

aaron@aaron-Raytine-PC:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)
Copyright © 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>

3. Unable to log in after installation

3.1 Reasons

Reason one (mostly):

You installed it as root: Enter: mysql -uroot on the local command line to log in directly, and then modify the user name and password.

Reason two:

Use the mysql -u root -p command but do not know the root password because it has not been set before. At this time, configure the environment and set the root password.

1. First, log in by ignoring the password and open the configuration file

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

2. Add skip-grant-tables at the end

#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
skip-grant-tables
-- 插入 --           

3. Save and exit

4. Restart the following mysql services

sudo service mysql stop

sudo service mysql start

5. Log in again

mysql -u mysql

Go to step 3.2, and comment out skip-grant-tables after all steps are executed

Reason 3: Did not uninstall the previous mysql cleanly

Remove MySQL completely

Before deleting mysql, you need to delete /var/lib/mysql and /etc/mysqlubuntu

Stop the mysql service first

systemctl stop mysql

Need to enter the following commands

sudo rm /var/lib/mysql/ -R 
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

Make sure there is no mysql folder to ignore this step

sudo find / -name mysql

install again

sudo apt-get install mysql-server          //服务端
sudo apt-get install mysql-client          //客户端
sudo apt-get install libmysqlclient-dev    //程序编译时链接的库

3.2 Switch database after login

Log in

~$ sudo mysql -u root -p
Enter password: 

Enter directly

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.39-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Change to database

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 

3.3 Change the password (note that the account number and password are in double quotes)

mysql> update user set authentication_string=PASSWORD("123456") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

3.4 Check the user

select user,host from mysql.user;

When the following information appears, the configuration is complete

mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

3.5 Then refresh to make the configuration take effect

flush privileges;

3.6 Exit

quit

3.7 restart

sudo service mysql restart

Three, mysql use test

1. Create a database

mysql> create database joyrun;
Query OK, 1 row affected (0.00 sec)

2. View the current database

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| joyrun             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

3. Create a table

mysql> use joyrun
Database changed
mysql> create table tbl_run(id int,name varchar(5),primary key (id));
Query OK, 0 rows affected (0.01 sec)

4. View the structure of the table

mysql> desc tbl_run;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| id    | int(11)    | NO   | PRI | NULL    |       |
| name  | varchar(5) | YES  |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

5. Modify the byte length

mysql> alter table tbl_run modify column name varchar(20);
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc tbl_run;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

6. Chinese fields cannot be added to the table now, only after modifying the character set

修改库字符集:alter database joyrun character set utf8;

修改表字符集:alter table tbl_run character set utf8;

修改字段字符集:alter table tbl_run change name name varchar(20) character set utf8;

7. Add a piece of data

mysql> insert into tbl_run (id,name) values (1,'xiaoming');
Query OK, 1 row affected (0.01 sec)
mysql> select * from tbl_run;
+----+----------+
| id | name     |
+----+----------+
|  1 | xiaoming |
+----+----------+
1 row in set (0.00 sec)

Supongo que te gusta

Origin blog.csdn.net/qq_43445867/article/details/126718980
Recomendado
Clasificación