LAMP架构安装——二进制安装MySQL

二进制格式安装MySQL

  • 下载二进制格式的MySQL软件包,推荐从MySQL官方网站下载
//推荐下载MySQL5.7.31的版本
[root@server ~]# cd /usr/src/
[root@server src]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
...

//创建用户和组
[root@server src]# useradd -r -M -s /sbin/nologin mysql

//解压软件至/usr/local目录下,目录的位置可以是其他的地方
[root@server src]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server src]# ls /usr/local
bin  games    lib    libexec  mysql-5.7.31-linux-glibc2.12-x86_64  share
[root@server usr]# ll -d /usr/local/mysql*
lrwxrwxrwx 1 root root   36 Oct 22 15:07 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/
drwxr-xr-x 9 7161 31415 129 Jun  2 21:11 mysql-5.7.31-linux-glibc2.12-x86_64

//修改修改目录/usr/local/mysql的属主属组
[root@server usr]# cd local/
[root@server local]# chown -R mysql.mysql mysql*
[root@server local]# ll -d mysql*
lrwxrwxrwx 1 mysql mysql  36 Oct 22 15:07 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/
drwxr-xr-x 9 mysql mysql 129 Jun  2 21:11 mysql-5.7.31-linux-glibc2.12-x86_64

//添加环境变量
[root@server usr]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@server usr]# source /etc/profile.d/mysql.sh 
[root@server usr]# echo $PATH
/usr/local/mysql/bin:/usr/local/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//配置MySQL
[root@server ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@server ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@server ~]# ldconfig      
//建立数据存放目录
[root@server ~]# mkdir /data
[root@server ~]# chown -R mysql.mysql /data/

//初始化数据库
[root@server local]# mysqld --initialize --user=mysql --datadir=/data
2020-10-22T07:45:46.801098Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-10-22T07:45:47.932788Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-10-22T07:45:47.968206Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-10-22T07:45:48.036912Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9977fed3-143a-11eb-ac64-000c29340c82.
2020-10-22T07:45:48.038426Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-10-22T07:45:48.386426Z 0 [Warning] CA certificate ca.pem is self signed.
2020-10-22T07:45:48.746496Z 1 [Note] A temporary password is generated for root@localhost: rtG*bw3mq(*F  		
//注意这里有一个临时密码rtG*bw3mq(*F,一会登录的时候要用,这个临时密码是随机生成的


//生成配置文件
[root@server ~]# vim /etc/my.cnf				#如果这个文件存在,请先备份再修改
[mysqld]
basedir = /usr/local/mysql
datadir = /data
socket = /tmp/mysql.sock
port = 3306
pid-file = /data/mysql.pid
user = mysql
skip-name-resolve

//配置服务启动脚本
[root@server ~]# cp -a /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@server ~]# vim /etc/init.d/mysqld  			#修改文件中的这两个地方
basedir=/usr/local/mysql
datadir=/data

//启动mysql服务,并设置为开机自动启动
[root@server ~]# service mysqld start 
Starting MySQL.Logging to '/data/server.err'.
. SUCCESS! 
[root@server ~]# ss -antl|grep 3306
LISTEN   0         80                        *:3306                   *:*   
[root@server ~]# chkconfig --add mysqld
[root@server ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:on
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

//使用临时密码登录mysql,然后修改密码
[root@server ~]# mysql -uroot -p'rtG*bw3mq(*F'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//如果出现这样的问题可以尝试通过yum安装ncurses-compat-libs这个库

//设置新密码
mysql> set password = password('redhat123+');
Query OK, 0 rows affected, 1 warning (0.00 sec)
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页