秉承菜鸟原则,阅读菜鸟文档,菜鸟文档地址如下;在学习过程中遇到一些无记录的错误;
MySQL 安装 | 菜鸟教程
版本】
![b3ec0512da0df33550efc0d63ac37bf8.png](https://i-blog.csdnimg.cn/blog_migrate/552cfefd062b5756f38d3161dcf5a159.png)
CentOs】
![8b7f7ce5d12e1e07ab064580bf4a7c37.png](https://i-blog.csdnimg.cn/blog_migrate/9501d689a0649c399e3e8debfdc8924d.png)
![67e8f4953ae17a9dfd0fc2be29b3eafb.png](https://i-blog.csdnimg.cn/blog_migrate/becad70b623fb99dbcc55dac50f39f25.jpeg)
1,这一步时,先点击该链接查看.rpm版本是否存在,记录版本名称再使用wget进行下载;
2,使用wget命令时,如果失败,可能是未安装wget, 【yum -y install wget 下载wget】;
安装命令】wget https://dev.mysql.com/get/mysql57-community-release-el7-
9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server
![77b5e64515c975f9cfce87b873a83646.png](https://i-blog.csdnimg.cn/blog_migrate/eb697f910b50d1501acba69b98084877.png)
![66a603d1ceb3330e3e99fb0a83f0014c.png](https://i-blog.csdnimg.cn/blog_migrate/9e54944ad6946a0a5017228c0905de81.png)
1,注意Linux和MySQL的版本,某些版本的MySQL服务data目录已存在数据,所以创建失败
vi /etc/my.cnf , 查看data目录是否存在文件内容信息;得到【datadir】路径信息;
vim /etc/my.cnf
[root@localhost mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# 5.1.2 Server Configuration Defaults
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
"/etc/my.cnf" 30L, 1188C
2,解决:
cd /var/lib/mysql ,进入该目录;查看文件信息;
rm -rf xx;清空目录下所有信息;
mysqld initialize,初始化mysql 成功;
![cd049594c6f7268c6ef4074b87e09c34.png](https://i-blog.csdnimg.cn/blog_migrate/a357e538bf7705cd2711be26e5d9cb3b.png)
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
1,查找/var/lib/mysql是否存在mysql.lock文件,cd /var/lib/mysql && ls -l 无文件
2,解决方法【登录mysql出现/var/lib/mysql/mysql.sock不存在 - okstill - 博客园】
systemctl stop mysqld (停止服务)
rm -fr /var/lib/mysql/* (删除/var/lib/mysql下的所有文件)
killall mysqld (杀死所有mysqld进程) ,解决方法:
先查看MySQL进程是否存在,ps -ef | grep mysql】,只杀掉mysql的进程,kill -9 9346
版本1
![c365445ecf9d4f96e31f36178edc4d22.png](https://i-blog.csdnimg.cn/blog_migrate/4b06cebfbf166efc3e878b6df427ef22.png)
版本2
![0763fec498afc76828aafaf4fdad966c.png](https://i-blog.csdnimg.cn/blog_migrate/669a81a811376348edbcecb6c60c79b7.png)
说明,
systemctl start mysqld (启动mysql服务。)
补充进程命令替换4.4【ps aux | grep mysql 】,强行终止当前用户使用得进程[kill -9 xx]
再次MySQL,提示密码错误,有两种方法,下面是最直接得一种;
编辑/etc/my.cnf 末尾加上skip-grant-tables【免密登陆】
![8fd3002d396b9ea5a2b2a442072bcf3d.png](https://i-blog.csdnimg.cn/blog_migrate/64e495e00b6162644377d8cbdd8df255.png)
出现mysql>说明成功进入MySQL;
![cb326cb888e31fe711d99f7276a793c1.png](https://i-blog.csdnimg.cn/blog_migrate/91dcd0d3f6b4c946f936b2e0ca24b86f.png)
刚才通过设置/etc/my.cnf文件来免密登陆,在生产环境是不行得,所以要配置用户密码;
(mysql密码要求【不低于8位,必须有数字,(大小)字母,特殊字符,】)
第二种方法,【grep 'temporary password' /var/log/mysqld.log】
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2018-07-06T09:21:46.580093Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,-fY)u_&j0yC
密码就是host:后面部分(动态密码保存在lysqld日志内部,用此密码可不配置免密登陆);
[登陆命令]mysql -u root -p
[输入密码] xxxxxxx
1,登陆后,查看数据库【SHOW DATABASE;】
提示修改临时密码,否则不能查看成功;下方是网站例子,输入后提示命令与版本发生错误;
![93a0265e54ba8a45f9decdd95c4ac56e.png](https://i-blog.csdnimg.cn/blog_migrate/ebb5d8856c5960a2707e945ebe3b8441.png)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqladmin -u root password "25752575&Yzp"' at line 1
2,使用命令【ALTER user 'root'@'localhost' IDENTIFIED BY '25752575&Yzp';】
![ad6e747060c22fdc6a9149cb0cc1374e.png](https://i-blog.csdnimg.cn/blog_migrate/ae32a409b6f013787e6eb3978632d52a.png)
![755cf6ba547ab286119009157e46aa52.png](https://i-blog.csdnimg.cn/blog_migrate/9dd259da27068c99aefd20225f417371.png)
![ac2ffb4a9e5ae7b73fecab3973e2d1cd.png](https://i-blog.csdnimg.cn/blog_migrate/e141f8efe4ddfc6a5a919132db7e5ac0.png)
更新后的密码登陆成功,sql命令正常使用无错误信息;
-----------------------------------------------------------------------------------------------
昨天帮同事安装另一个版本的mysql【mysql-5.7.13-linux-glibc2.5-x86_64】,头疼;
参考资料【Linux 系统安装下安装 mysql5.7(glibc版)】
下载MySQL的安装包;
下载安装 libaio;
编写配置文件/etc/my.cnf;
[mysql]
#skip-name-resolve
#设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock 注意这个地方,我这么写在登陆的时候一直报错,
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
#default-storage-engine=INNODB
#lower_case_table_name=1
max_allowed_packet=16M
报错内容如下:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2);
经过检查,发现/var/lib/mysql/mysql.sock确有该文件存在,但一直提示连接不上,索性把my.cnf的socket=/tmp/mysql.sock,这样就好了,成功登陆;