千家信息网

mysql编译安装及其它

发表于:2025-01-18 作者:千家信息网编辑
千家信息网最后更新 2025年01月18日,下文内容主要给大家带来mysql编译安装及其它,这里所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。编译安装MySQL1、
千家信息网最后更新 2025年01月18日mysql编译安装及其它

下文内容主要给大家带来mysql编译安装及其它,这里所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。

编译安装MySQL

1、安装MySQL需要的依赖包和编译软件

(1)安装MySQL需要的依赖包

#yum install ncurses-devel libaio-devel -y

(2)安装编译MySQL需要的软件

#ls -lh cmake-2.8.8.tar.gz
#tar xf cmake-2.8.8.tar.gz
#cd cmake-2.8.8
#./configure
#gmake && gmake install

或者直接yum安装

#yum install cmake -y

2、开始安装MySQL

(1)建立MySQL用户帐号

#useradd -s /sbin/nologin -M mysql

(2)获取MySQL软件包

http://mirrors.sohu.com/

(3)采用编译方式安装MySQL

#tar xf mysql-5.5.49.tar.gz
#cd mysql-5.5.49
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.49\-DMYSQL_DATADIR=/application/mysql-5.5.49/data \-DMYSQL_UNIX_ADDR=/application/mysql-5.5.49/tmp/mysql.sock\-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \-DENABLED_LOCAL_INFILE=ON \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \-DWITH_FAST_MUTEXES=1 \-DWITH_ZLIB=bundled \-DENABLED_LOCAL_INFILE=1 \-DWITH_READLINE=1 \-DWITH_EMBEDDED_SERVER=1 \-DWITH_DEBUG=0
#make && make install
#ln -s /application/mysql-5.5.49/ /application/mysql

数据库配置文件

#mkdir -p /data/3306/data
#vim /data/3306/my.cnf
[client]port           = 3306socket         = /data/3306/mysql.sock[mysql]no-auto-rehash[mysqld]user    =mysqlport    =3306socket  =/data/3306/mysql.sockbasedir = /application/mysqldatadir = /data/3306/dataopen_files_limit   = 1024back_log = 600max_connections = 800max_connect_errors = 3000table_cache = 614external-locking = FALSEmax_allowed_packet =8Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2Mquery_cache_limit = 1Mquery_cache_min_res_unit = 2k#default_table_type = InnoDBthread_stack = 192K#transaction_isolation = READ-COMMITTEDtmp_table_size = 2Mmax_heap_table_size = 2Mlong_query_time = 1#log_long_format#log-error = /data/3306/error.log#log-slow-queries = /data/3306/slow.logpid-file = /data/3306/mysql.pidlog-bin = /data/3306/mysql-binrelay-log = /data/3306/relay-binrelay-log-info-file = /data/3306/relay-log.infobinlog_cache_size = 1Mmax_binlog_cache_size = 1Mmax_binlog_size = 2Mexpire_logs_days = 7key_buffer_size = 16Mread_buffer_size = 1Mread_rnd_buffer_size = 1Mbulk_insert_buffer_size = 1M#myisam_sort_buffer_size = 1M#myisam_max_sort_file_size = 10G#myisam_max_extra_sort_file_size = 10G#myisam_repair_threads = 1#myisam_recoverlower_case_table_names = 1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db=mysqlserver-id = 1innodb_additional_mem_pool_size = 4Minnodb_buffer_pool_size = 32Minnodb_data_file_path = ibdata1:128M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 2Minnodb_log_file_size = 4Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 2M[mysqld_safe]log-error=/data/3306/mysql_3306.errpid-file=/data/3306/mysqld.pid

数据库启动文件

#vim /data/3306/mysql
#!/bin/sh################################################ #initport=3306mysql_user="root"mysql_pwd="123456"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup functionfunction_start_mysql(){      if [ ! -e"$mysql_sock" ];then      printf "StartingMySQL...\n"    /bin/sh${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &    else      printf "MySQL isrunning...\n"      exit    fi} #stop functionfunction_stop_mysql(){    if [ ! -e"$mysql_sock" ];then       printf "MySQL isstopped...\n"       exit    else       printf "StopingMySQL...\n"${CmdPath}/mysqladmin -u${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown   fi} #restart functionfunction_restart_mysql(){    printf "RestartingMySQL...\n"    function_stop_mysql    sleep 2    function_start_mysql} case $1 instart)    function_start_mysql;;stop)    function_stop_mysql;;restart)    function_restart_mysql;;*)    printf "Usage:/data/${port}/mysql {start|stop|restart}\n"esac


修改文件权限

#chown -R mysql.mysql /data
#find /data -name mysql|xargs chmod 700


配置全局路径

#echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
#source /etc/profile

初始化数据库

#cd /application/mysql/scripts
./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql

启动数据库

/data/3306/mysql start

登录数据库

#mysql -S /data/3306/mysql.sock

修改数据库登录密码

#mysqladmin -u root -S /data/3306/mysql.sock password '123456'
#mysql -uroot -p123456 -S /data/3306/mysql.sock


降权启动

#find /data -type f -name "mysql"|xargs chmod 700
#find /data -type f -name "mysql" -exec chown root.root {} \;

设置开机自启

#echo "#mysql multi instances">>/etc/rc.local
#echo "/data/3306/mysql start">>/etc/rc.local


删除不需要的数据库

>select user,host from mysql.user;
>drop user 'root'@'::1';
>drop user ''@'db01';
>drop user 'root'@'db01';
>drop user ''@'localhost';
>select user,host from mysql.user;

>flush privileges;

对于以上关于mysql编译安装及其它,如果大家还有更多需要了解的可以持续关注我们的行业推新,如需获取专业解答,可在官网联系售前售后的,希望该文章可给大家带来一定的知识更新。

0