本文主要简单介绍下在ubutnu上面mysql的检测,安装,启动的相关步骤和注意事项.
一: 检测PC上是否安装了mysql如下是没有安装的情况
useful reference:
https://stackoverflow.com/questions/27614574/how-can-i-check-if-mysql-is-installed-on-ubuntu
如下是没有安装的情况:
$ dpkg -s mysql-server | grep Status
dpkg-query: package 'mysql-server' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
$ mysql
The program 'mysql' can be found in the following packages:
* mysql-client-core-5.7
* mariadb-client-core-10.0
Try: sudo apt install <selected package>
二: 安装mysql
useful reference:
https://www.linode.com/docs/databases/mysql/install-mysql-on-ubuntu-14-04/
http://www.runoob.com/mysql/mysql-install.html
https://www.ilanni.com/?p=13197
step 1:
sudo apt-get update
sudo apt-get upgrade
step2:
sudo apt-get install mysql-server mysql-client
其中mysql-server是mysql服务器, 可以在本机上实现数据库相关服务.
mysql-client 是客户端程序, 用于连接并操作mysql server. 如果你不需要在本地建立数据库, 只需要远程连接操作在另一台机器上的mysql server那就只需要安装mysql client.
过程中会提示你设置一个mysql 的root密码.
step3: 登录
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2017, 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>
(之前安装的时候设置了root用户的password. 此时如果你的PC当前用户是root可以直接用命令mysql登录, 如果你的PC当前用户不是root, 就要用mysql -u root -p, 再输入密码登录.)
恭喜你安装成功啦.
三: mysql安装后
1: 安装状态
$ dpkg -s mysql-server | grep Status
Status: install ok installed
$ dpkg -s mysql-client | grep Status
Status: install ok installed
$ dpkg --get-selections | grep mysql
libdbd-mysql-perl install
libmysqlclient18:amd64 install
libmysqlclient18:i386 install
libqt4-sql-mysql:i386 install
mysql-client install
mysql-client-5.5 install
mysql-client-core-5.5 install
mysql-common install
mysql-server install
mysql-server-5.5 install
mysql-server-core-5.5 install
$ dpkg --get-selections | grep mysql
libmysqlclient18:i386 install
libqt4-sql-mysql:i386 install
mysql-client-core-5.5 install
mysql-common install
$ sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 2610/mysqld
2: 安版本的检测
(1) 在终端运行
$ mysql -V或者 mysql --version
mysql Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3
$ mysql --help |grep Distrib
mysql Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3
(2) 登录mysql查看
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.5.55-0ubuntu0.14.04.1 |
+-------------------------+
1 row in set (0.00 sec)
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.55, for debian-linux-gnu (x86_64) using readline 6.3
Connection id: 47
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 2 days 17 hours 33 min 28 sec
Threads: 1 Questions: 586 Slow queries: 0 Opens: 189 Flush tables: 1 Open tables: 41 Queries per second avg: 0.002
3: configuration配置相关
下面有几个mysql比较重要的目录以及文件.
(1) 数据库的存放目录
/var/lib/mysql (默认) 该路径下面你可以看到你创建的数据库, 可以通过配置文件更改保存路径. 下次介绍更改步骤.
(2) 配置文件
/usr/share/mysql
/etc/mysql/my.cnf (非常重要)
(3) 相关重要命令
/usr/bin
root@ubuntu:/usr/bin# ls *sql*
msql2mysql mysql_convert_table_format mysql_install_db mysql_setpermission mysql_waitpid mysqladmin mysqlbug mysqld_safe mysqlhotcopy mysqlrepair mysqlslap
mysql mysql_find_rows mysql_plugin mysql_tzinfo_to_sql mysql_zap mysqlanalyze mysqlcheck mysqldump mysqlimport mysqlreport mysqltest
mysql_client_test mysql_fix_extensions mysql_secure_installation mysql_upgrade mysqlaccess mysqlbinlog mysqld_multi mysqldumpslow mysqloptimize mysqlshow
(4) 启动脚本
/etc/init.d/mysql
Tips: 之前在检测版本的时候我遇到了一个问题, 如下是问题以及解决方法,希望对大家有帮助.
$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)