源码安装mysql
admin
2023-05-18 13:42:29
0次

创建mysql组:
groupadd mysql

创建mysql用户并赋予这个mysq组中,不创建家目录,不允许用户登录。(因为刚刚创建的mysql是虚拟用户,所以不允许登录)
useradd mysql -g mysql -M -s /bin/nologin

源码安装mysql
解压后进行编译安装:
./configure \
--prefix=/application/mysql5.1.72 \
--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/application/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static

make && make make install


安装好后 创建mysql的软链接:
ln -s /application/mysql5.1.72/ /application/apache

在该目录下查看/usr/local/tools/mysql-5.1.72/support-files/下面cnf的配置文件    这些文件都是默认的配置文件的模版,适合与不同的场景
[root@node1 support-files]# ll  my*.cnf
-rw-r--r-- 1 root root  4746 05-04 02:49 my-huge.cnf         第四小            这些是根据服务器的硬件配置来衡量,服务器硬件过低,用最小的,配置高,用最大
-rw-r--r-- 1 root root 19779 05-04 02:49 my-innodb-heavy-4G.cnf     最大的
-rw-r--r-- 1 root root  4720 05-04 02:49 my-large.cnf        第三小
-rw-r--r-- 1 root root  4731 05-04 02:49 my-medium.cnf       最小的
-rw-r--r-- 1 root root  2499 05-04 02:49 my-small.cnf        第二小
然后将其中选择适合你的服务器的配置文件拷贝到/etc下
[root@node1 support-files]# cp my-small.cnf /etc/my.cnf

创建mysql数据库存放数据的目录:
[root@node1 ~]# mkdir  /application/mysql/data -p

给/application/mysql/目录授予mysql用户和mysql组的权限
[root@node1 ~]# chown -R mysql.mysql  /application/mysql/

初始化数据文件
[root@node1 ~]#/application/mysql/bin/mysql_install_db  --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

plication/mysql/data/ --user=mysql
Installing MySQL system tables...
170504  4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
170504  4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h node1.com password 'new-password'

Alternatively you can run:
/application/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql//scripts/mysqlbug script!


现在mysql就已经安装完成,到data目录下查看会生成两个库:
[root@node1 ~]# ll /application/mysql/data/
总计 8
drwx------ 2 mysql root 4096 05-04 04:34 mysql     系统的库,
drwx------ 2 mysql root 4096 05-04 04:34 test      测试的库,建议删除,不安全。

[root@node1 init.d]# /application/mysql//bin/mysqld_safe &
[1] 17071
[root@node1 init.d]# 170504 04:48:46 mysqld_safe Logging to '/application/mysql5.1.72/data/node1.com.err'.
170504 04:48:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql5.1.72/data

[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]# netstat -tulnp | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17179/mysqld        




启动mysql 以start方式启动
[root@node1 init.d]# cp /usr/local/tools/mysql-5.1.72/support-files/mysql.server /etc/init.d/mysqld
[root@node1 init.d]# chmod +x /etc/init.d/mysqld

保存之后就可以启动了。



mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;    
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
|      | localhost |
| root | localhost |
|      | node1.com |
| root | node1.com |
+------+-----------+
5 rows in set (0.00 sec)

mysql> drop user ""@localhost
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user ""@node1.com
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| root | node1.com |
+------+-----------+
3 rows in set (0.00 sec)

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...