Debian之MySQL
在Fedora和RedHat以及CentOS中 源码编译安装MySQL5.6.12详细过程
mysql-server 与 mysql-client
mysql-server 与 mysql-client是DBMS的两个面向不同操作对象的工具。
server是DBMS面向物理层次,包含存储数据的一系列机制、处理方法的集成;
client是DBMS面向用户,提供一系列工具为用户所用,这些工具包括通常写的sql在内都要通过server的编译才能操作物理数据。
mysql-server是服务端,也就是说,你服务端没安装,客户端没对象去操作,就好比,你买了个西瓜刀,但是却没买西瓜。。。。切西瓜有很多工具,西瓜刀只是其中一种
介绍几个主流mysql图形化客户端,navicat,phpmyadmin
rpm包安装完后自动将mysql安装成系统服务,所以可以使用下面命令启动、停止mysql
启动mysql
/etc/init.d/mysql start 或 service mysql start
相关目录
工具程序(mysqladmin mysqldump等命令)在/usr/bin目录中---ls /usr/bin/mysql*
服务器程序/usr/sbin/mysqld
数据目录 /var/lib/mysql
错误日志文件、二进制日志文件及进程文件写在/var/lib/mysql目录中
mysql.server命令及配置文件 /usr/share/mysql
配置
root@localhost:/etc/mysql# ls
conf.d debian-start mariadb.conf.d my.cnf.fallback
debian.cnf mariadb.cnf my.cnf
配置说明
/etc/my.cnf文件中说明
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
卸载
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
sudo rm /var/lib/mysql/ -R //非常重要
sudo rm /etc/mysql/ -R //非常重要
安装
sudo apt-get install mysql-server
上述命令会安装以下包:
apparmor
mysql-client-5.7
mysql-common
mysql-server
mysql-server-5.7
mysql-server-core-5.7
root@localhost:~# whereis mysql
mysql: /usr/bin/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
查看服务当前状态 systemctl命令
systemctl status mysql.service
确认是否启动成功:
netstat命令用来打印Linux中网络系统的状态信息,netstat命令
root@localhost:~# sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 18305/mysqld
主要配置
sudo mysql_secure_installation
- Enter current password for root (enter for none): (第一次没有密码)
- Set root password? [Y/n] y (设置 root 密码)
- Remove anonymous users? [Y/n] y (移除匿名账户)
- Disallow root login remotely? [Y/n] y (禁用 root 远程登录)
- Remove test database and access to it? [Y/n] y (删除 test 数据库和访问权限)
- Reload privilege tables now? [Y/n] y (刷新权限)
show databases; 显示数据库
show tables; 显示数据库中的表
describe 表名; 显示数据表的结构:
create database 表名; 建数据库
/etc/init.d/mysql start 启动
service mysql stop 关停mysql服务
/usr/bin/mysqladmin -u root -p shutdown 停止
service mysql restart 重启mysql服务
/var/lib/mysql MySQL默认的数据文件存储目录
sudo netstat -tap | grep mysql
试过一次,没成功
dpkg: error processing package mysql-community-server (--remove):
package is in a very bad inconsistent state; you should
reinstall it before attempting a removal
Errors were encountered while processing:
mysql-community-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@localhost:/var/lib/apt/lists#
The package mysql-community-server needs to be reinstalled, but I can't find an archive for it
dpkg --remove --force-remove-reinstreq mysql-community-server