VMware上安装MySQL
阅读原文时间:2021年04月20日阅读:1

安装命令加日志:
命令总结:
1,安装命令(下面的逐一运行):
sudo apt-get install mysql-server
sudo apt-get isntall mysql-client
sudo apt-get install libmysqlclient-dev
2,检查是否安装成功:
sudo netstat -tap | grep mysql
结果截图:

日志:

zhouyi@ubuntu:~$ sudo apt-get install mysql-server
[sudo] password for zhouyi: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  snapd-login-service
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
 libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7
  mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
 libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7
 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
 mysql-server-core-5.7
0 upgraded, 9 newly installed, 0 to remove and 53 not upgraded.
Need to get 18.7 MB of archives.
After this operation, 161 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-common all 5.7.26-    0ubuntu0.16.04.1 [15.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client-core-5.7 amd64 5.7.26-0ubuntu0.16.04.1 [6,388 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client-5.7 amd64 5.7.26-0ubuntu0.16.04.1 [1,834 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-server-core-5.7 amd64 5.7.26-0ubuntu0.16.04.1 [7,471 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libevent-core-2.0-5 amd64 2.0.21-stable-2ubuntu0.16.04.1 [70.6 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-server-5.7 amd64 5.7.26-0ubuntu0.16.04.1 [2,831 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2 [60.4 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-server all 5.7.26-    0ubuntu0.16.04.1 [10.8 kB]
Fetched 18.7 MB in 10s (1,756 kB/s)                                            
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 216512 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.7.26-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-common (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package libaio1:amd64.
Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...
Unpacking libaio1:amd64 (0.3.110-2) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../mysql-client-core-5.7_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server-core-5.7.
Preparing to unpack .../mysql-server-core-5.7_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package libevent-core-2.0-5:amd64.
Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...
Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-common (5.7.26-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto         mode
Selecting previously unselected package mysql-server-5.7.
(Reading database ... 216680 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...
Unpacking libhtml-template-perl (2.95-2) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.26-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.26-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.21) ...
Setting up libaio1:amd64 (0.3.110-2) ...
Setting up mysql-client-core-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Setting up mysql-client-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Setting up mysql-server-core-5.7 (5.7.26-0ubuntu0.16.04.1) ...
Setting up libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.26-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Setting up libhtml-template-perl (2.95-2) ...
Setting up mysql-server (5.7.26-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.21) ...
zhouyi@ubuntu:~$ apt-get install mysql-client
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
zhouyi@ubuntu:~$ sudo apt-get install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  snapd-login-service
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  mysql-client
0 upgraded, 1 newly installed, 0 to remove and 53 not upgraded.
Need to get 10.0 kB of archives.
After this operation, 110 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client all 5.7.26-    0ubuntu0.16.04.1 [10.0 kB]
Fetched 10.0 kB in 0s (14.0 kB/s)      
Selecting previously unselected package mysql-client.
(Reading database ... 216781 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.26-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.26-0ubuntu0.16.04.1) ...
Setting up mysql-client (5.7.26-0ubuntu0.16.04.1) ...
zhouyi@ubuntu:~$ sudo apt-get install libmysqlclient-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
 snapd-login-service
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
 libmysqlclient20 zlib1g-dev
The following NEW packages will be installed:
  libmysqlclient-dev libmysqlclient20 zlib1g-dev
0 upgraded, 3 newly installed, 0 to remove and 53 not upgraded.
Need to get 2,136 kB of archives.
After this operation, 11.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libmysqlclient20 amd64 5.7.26-0ubuntu0.16.04.1 [812 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-2ubuntu4.1 [168 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libmysqlclient-dev amd64 5.7.26-0ubuntu0.16.04.1 [1,156 kB]
Fetched 2,136 kB in 21s (101 kB/s)                                             
Selecting previously unselected package libmysqlclient20:amd64.
(Reading database ... 216785 files and directories currently installed.)
Preparing to unpack .../libmysqlclient20_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking libmysqlclient20:amd64 (5.7.26-0ubuntu0.16.04.1) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../zlib1g-dev_1%3a1.2.8.dfsg-2ubuntu4.1_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ...
Selecting previously unselected package libmysqlclient-dev.
Preparing to unpack .../libmysqlclient-dev_5.7.26-0ubuntu0.16.04.1_amd64.deb ...
Unpacking libmysqlclient-dev (5.7.26-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libmysqlclient20:amd64 (5.7.26-0ubuntu0.16.04.1) ...
Setting up zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ...
Setting up libmysqlclient-dev (5.7.26-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
zhouyi@ubuntu:~$ sudo netstat -tap | gerp mysql
No command 'gerp' found, did you mean:
 Command 'grep' from package 'grep' (main)
gerp: command not found
zhouyi@ubuntu:~$ sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         *:*                     LISTEN      16781/mysqld    
zhouyi@ubuntu:~

安装好了,如何登陆呢?

登陆日志:我们用用户名加密码登陆:mysql -u root -p,键入密码即可。进入后查库:show databases;(这里分号不能省去) use mysql 命令选择使用数据库;显示当前数据库的表单:show tables 等等。

zhouyi@ubuntu:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

创建数据库,并使用:

#创建
mysql> create database xxx;
#使用
use xxx

常用命令:关闭,启动

[root@centos6 etc]# service mysql stop
Shutting down MySQL...                                

[root@centos6 etc]# service mysql start
Starting MySQL...                                    

[root@centos6 etc]# service mysql restart
Shutting down MySQL.                                   
Starting MySQL..                                         
[root@centos6 etc]# 

退出mysql命令

mysql> quit

查看位置:

whereis mysql

结构分析:比(1是表在数据库中,2是有如下数据库)


数据结构:

这里要特别说明一点不要直接在XShell上写sql文。因为很容易一不小心就删掉了。建议用记事本或Notepad++写好了直接复制运行。
特别注意数据库操作每一步执行最后要加上分号“;”。

解决报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

#解决方式
root@ubuntu:/home/zhouyi# chown -R mysql:mysql /var/lib/mysql
root@ubuntu:/home/zhouyi# /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.

解决A2M5不能连接虚拟机数据库问题:
端口查看结果:利用cmd进行telnet测试,发现不可用。

mysql> show variables like '%port%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_support_xa        | ON    |
| large_files_support      | ON    |
| port                     | 3306  |
| report_host              |       |
| report_password          |       |
| report_port              | 3306  |
| report_user              |       |
| require_secure_transport | OFF   |
+--------------------------+-------+
8 rows in set (0.14 sec)

解决telnet 不可用问题:

测试结果:(端口没有启用)

Microsoft Windows [版本 10.0.17134.829]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\zy962>telnet 192.168.253.131 3306
'telnet' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\zy962>telnet 192.168.253.131 3306
正在连接192.168.253.131...无法打开到主机的连接。 在端口 3306: 连接失败

C:\Users\zy962>

解决方式:进入mysql配置文件,注释掉:127.0.0.1

远程连接虚拟机数据库访问:
原因:一般mysql是不允许除了本机用户以外的用户进行访问的,所以需要给特定ip的用户开放权限,通过这个用户去访问连接
创建用户并附有所有权限:

mysql> create user 'activiti'@'%' identified by 'activiti';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'activiti'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

并没有成功连接,有空再来!

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章