Ubuntu
1、卸载系统上的mysql
rpm -e mysql // 普通删除模式
rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
2、下载rpm安装包:wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3、解压rpm包:rpm -ivh mysql-community-release-el7-5.noarch.rpm
4、apt-get命令安装mysql-server
5、初始化 MySQL:mysqld --initialize
6、启动mysql:sudo /etc/init.d/mysql start
7、查看mysql状态:service mysql status
Centos
使用yum安装
参考:https://blog.csdn.net/lpl_lpl_lpl/article/details/86479502
rpm包安装MySQL8
1、卸载自带的MySQL
查看自带的MySQL:rpm -qa | grep -i mysql
卸载自带的MySQL:rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps
2、安装MySQL依赖环境:yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel net-tools* numactl*
3、添加MySQL用户:
groupadd mysql
useradd -g mysql mysql
4、下载MySQL8 rpm包:wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-1.el6.x86_64.rpm-bundle.tar
5、解压下载的安装包:tar xvf mysql-8.0.18-1.el6.x86_64.rpm-bundle.tar
6、按照一下顺序安装:rpm -ivh XXX
mysql-community-common-8.0.18-1.el6.x86_64.rpm
mysql-community-libs-8.0.18-1.el6.x86_64.rpm
mysql-community-client-8.0.18-1.el6.x86_64.rpm
mysql-community-server-8.0.18-1.el6.x86_64.rpm
7、初始化数据库:
mkdir -p /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
8、启动sql服务:service mysqld start
9、启动MySQL时,会为MySQL的root账户生成临时登录密码,这个密码可以在/var/log/mysqld.log
文件中查看;找到如下代码
2019-11-18T08:16:12.451542Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -8cagKkdK#5G
10、使用临时密码登录:mysql -uroot -p-8cagKkdK#5G
11、修改root账号的密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
12、在MySQL命令行输入exit命令退出MySQL。使用修改后的root密码重新登录MySQL