在Linux中安装MySql数据库
1. 上传安装包
将rpm包上传到/root/work目录(也可以是其他目录)
MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm
2. 删除系统自带mysql
#查看之前是否安装过mysql
rpm -qa | grep -i mysql
#如果安装过,执行这行代码,删除之前安装过的mysql
rpm -ev --nodeps mysql-libs-5.1.71-1.el6.x86_64
3. 增加用户组
#增加用户组mysql
groupadd mysql
#增加用户mysql,加入mysql用户组
useradd -r -g mysql mysql
4. 安装
#安装server
rpm -ivh MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm
#安装client
rpm -ivh MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm
mysql5.6安装后所在的目录
Directory Contents of Directory
/usr/bin Client programs and scripts
/usr/sbin The mysqld server
/var/lib/mysql Log files, databases
/usr/share/info MySQL manual in Info format
/usr/share/man Unix manual pages
/usr/include/mysql Include (header) files
/usr/lib/mysql Libraries
/usr/share/mysql Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation
/usr/share/sql-bench Benchmarks
5. 修改配置
# 修改my.cnf,默认在/usr/my.cnf
vim /usr/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
6. 增加开机启动
#将mysqld加入系统服务,并随机启动
cp /usr/share/mysql/mysql.server /etc/init.d/mysqld
7. 启动服务
#启动mysqld
service mysqld start
8. 修改root默认密码
#获取mysql安装时root用户的随机密码
vim /root/.mysql_secret
#必须要修改root用户的密码才可以使用mysql,否则只能连接不能操作
mysqladmin -u root -p password root
9. 连接
#连接进入mysql
mysql -u root -p
root
MySql安装包网盘地址
链接:https://pan.baidu.com/s/1UJK1kKeV4VDZOTLSQ3Lw9A
提取码:e8kj