首页 > 其他分享 >MariaDB_installing,starting and stoping,configuring,logging in

MariaDB_installing,starting and stoping,configuring,logging in

时间:2023-06-19 16:33:10浏览次数:60  
标签:logging configuring installing server cnf file mysql MariaDB my


Installing MariaDB Binary Tarballs

via: https://mariadb.com/kb/en/installing-mariadb-binary-tarballs/

 

MariaDB Binary tarballs are named following the pattern: mariadb-VERSION-OS.tar.gz. Be sure to downloadthe correct version for your machine.



Note: Some binary tarballs are marked '(GLIBC_2.14)' or '(requires GLIBC_2.14+)'. These binaries are built the same as the others, but on a newer build host, and they require GLIBC 2.14 or higher. Use the other binaries for machines with older versions of GLIBC installed.



To install the binaries, unpack the distribution into the directory of your choice and run the mysql_install_dbscript.

In the example below we install MariaDB in the /usr/local/mysql directory (this is the default location for MariaDB for many platforms). However any other directory should work too.

We install the binary with a symlink to the original name. This is done so that you can easily change MariaDB versions just by moving the symlink to point to another directory.



NOTE: For MariaDB 5.1.32 only the line "./scripts/mysql_install_db --user=mysql" should be changed to "./bin/mysql_install_db --user=mysql"



Ensure you use the correct my.cnf files

MariaDB searches for the configuration files '/etc/my.cnf' (on some systems '/etc/mysql/my.cnf') and '~/.my.cnf'. If you have an old my.cnfThe normal solution for this is to ignore the my.cnf file in /etc

This is done by creating your own .my.cnf file in your home directory and telling mysql_install_dbmysqld_safe and possibly mysql (the command-line client utility) to only use this one with the option '--defaults-file=~/.my.cnf'. Note that this has to be first option for the above commands!

Installing MariaDB as root in /usr/local/mysql

If you have root access to the system, you probably want to install MariaDB under the user and group 'mysql' (to keep compatibility with MySQL installations):

groupadd mysql
useradd -g mysql mysql
cd /usr/local
tar -zxvpf /path-to/mariadb-VERSION-OS.tar.gz
ln -s mariadb-VERSION-OS mysql
cd mysql
./scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data

The symlinking with ln -s is recommended as it makes it easy to install many MariaDB version at the same time (for easy testing, upgrading, downgrading etc).

If you are installing MariaDB to replace MySQL, then you can leave out the call to mysql_install_db. Instead shut down MySQL. MariaDB should find the path to the data directory from your old /etc/my.cnf file (path may vary depending on your system).

To start mysqld you should now do:

./bin/mysqld_safe --user=mysql &
or
./bin/mysqld_safe --defaults-file=~/.my.cnf --user=mysql &

To test connection, modify your $PATH so you can invoke client such as mysql, mysqldump, etc.

export PATH=$PATH:/usr/local/mysql/bin/

You may want to modify your .bashrc or .bash_profile to make it permanent.

Installing MariaDB as not root in any directory

Below, change /usr/local to the directory of your choice.

cd /usr/local
gunzip < /path-to/mariadb-VERSION-OS.tar.gz | tar xf -
ln -s mariadb-VERSION-OS mysql
cd mysql
./scripts/mysql_install_db --defaults-file=~/.my.cnf

If you have problems with the above gunzip command line, you can instead, if you have gnu tar, do:



tar xfz /path-to/mariadb-VERSION-OS.tar.gz



To start mysqld you should now do:

./bin/mysqld_safe --defaults-file=~/.my.cnf &

Auto start of mysqld

You can get mysqld (the MariaDB server) to autostart by copying the file mysql.server file to the right place.



cp support-files/mysql.server /etc/init.d/mysql.server



 

The exact place depends on your system. The mysql.server file contains instructions of how to use and fine tune it.

Post installation

After this, remember to set proper passwords for all accounts accessible from untrusted sources, to avoid exposing the host to security risks! Also consider using the mysql.server to start MariaDB automatically when your system boots.

Our MariaDB binaries are similar to the Generic binaries available for the MySQL binary distribution. So for more options on using these binaries, the MySQL 5.5 manual entry on installing generic binaries can be consulted.

For details on the exact steps used to build the binaries, see the compiling MariaDB section of the KB.

 

 

Starting and Stopping MariaDB Automatically

via: https://mariadb.com/kb/en/iniciando-e-parando-mariadb-automaticamente/

 

When running MariaDB in a server environment it is almost always desirable to have MariaDB start automatically when the server is powered on, for it to stay running while the server is running, and for it to be shutdown gracefully when the server is shut down.

The actual MariaDB server binary is called mysqld. Like other MariaDB binaries, it is so named to preserve compatibility with upstream MySQL.

You have the option of starting the mysqld server several different ways:

  1. Run or invoke mysqld itself. An example of doing this is described more in Running MariaDB from the Source Directory.
  2. Use the mysqld_safe startup script
  3. Use the mysql.server startup script

The mysql.server script starts mysqld by first changing to the MariaDB install directory and then calling mysqld_safe. Adding an appropriate user line to the [mysqld] group in your my.cnf file will cause the server to be run as that user.

If you have installed MariaDB to a non-standard location, you may need to edit the mysql.server script to get it to work right.

mysql.server works as a standard SysV-style init script. As such you use the script with start and stoparguments like so:



mysql.server start mysql.server stop



To configure MariaDB to start and stop automatically on Linux using the mysql.server script you need to add it to your distribution's init system, usually by copying it to /etc/init.d/ and then creating specially named symlinks in the appropriate /etc/rcX.d/ directories (where 'X' is a number between 0 and 6).



In the examples below we will follow the historical convention of renaming the mysql.server script to 'mysql' when we copy it to /etc/init.d/.



The first step for most Linux distributions is to copy the mysql.server script to /etc/init.d/ and make it executable:

cd /path/to/your/mariadb-version/support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql

Now all that is needed is to create the specially-named symlinks. On both RPM and Debian-based Linux distributions there are tools which do this for you. Consult your distribution's documentation if neither of these work for you and follow their instructions for generating the symlinks or creating them manually.

On RPM-based distributions (like Fedora and CentOS), you use chkconfig:



chkconfig --add mysql chkconfig --level 345 mysql on



On Debian-based distributions you use update-rc.d:



update-rc.d mysql defaults



On FreeBSD, the location for startup scripts is /usr/local/etc/rc.d/ and when you copy the mysql.serverscript there you should rename it so that it matches the *.sh pattern, like so:

cd /path/to/your/mariadb/support-files/
cp mysql.server /usr/local/etc/rc.d/mysql.server.sh

As stated above, consult your distribution's documentation for more information on starting services like MariaDB at system startup.

See mysqld startup options for information on configuration options for mysqld.

 

Configuring MariaDB with my.cnf

via: https://mariadb.com/kb/en/configuring-mariadb-with-mycnf/

 

The my.cnf file allows you to configure MariaDB to run the way you want it. Most of the server system variablescan be set in the my.cnf file, although usually only a few are, and the rest simply take their default values.

Depending on how you've installed MariaDB, the my.cnf may be in a number of places, or it may not exist at all.

Location in Linux, Unix, Mac

On a Linux, Unix or Mac server, MariaDB looks for the my.cnf file in the following locations:



Location

Scope

/etc/my.cnf

Global

/etc/mysql/my.cnf

Global

SYSCONFDIR/my.cnf

Global

$MYSQL_HOME/my.cnf

Server

defaults-extra-file

File specified with --defaults-extra-file=path, if any

/.my.cnf

User



  • SYSCONFDIR is the directory specified with the CMake SYSCONFDIR option when MariaDB was built, by default 

etc

  • MYSQL_HOME is the environment variable containing the path to the directory holding the server-specific my.cnf file. If MYSQL_HOME is not set, and the server is started with mysqld_safe, MYSQL_HOME is set as follows:
  • If there is a my.cnf file in the MariaDB data directory, but not in the MariaDB base directory, MYSQL_HOME is set to the MariaDB data directory.
  • Else, MYSQL_HOME is set to the MariaDB base directory.

Location in Windows

On Windows, my.ini can be used as well as my.cnf, and MariaDB looks in the following locations.


Location

Scope

%PROGRAMDATA%\MySQL\MySQL Server x.x\my.cnf

Global (x.x refers to the version)

%WINDIR%\my.cnf

Global

C:\my.cnf

Global

INSTALLDIR\my.cnf

Global

defaults-extra-file

File specified with --defaults-extra-file=path, if any



  • %PROGRAMDATA% is the file system directory containing application data for all the host's users. It defaults to 

C:\ProgramData

  •  on modern versions of Windows, or to

C:\Documents and Settings\All Users\Application Data

  • %WINDIR% is the Windows directory, usually 

C:\WINDOWS

  • . To find its specific value on your system, use:

C:\> echo %WINDIR%



  • INSTALLDIR is the MariaDB installation directory from using the Windows installer, usually

C:\PROGRAMDIR\MySQL\MySQL 5.5 Server

  • , where PROGRAMDIR in turn is the programs directory, usually

Program Files

my.cnf hierarchy

MariaDB will look in all of the above locations, in order, even if has already found a my.cnf file, and it's possible for more than one my.cnf file to exist. For example, you can have a my.cnf file in /etc/mysql/my.cnf with global settings for all servers, and then another my.cnf file in the user's home directory, /my.cnf, which will add further (or overwrite) settings specific only to that user.

If no my.cnf file is found, the default values are used for all variables. See server system variables for a full list of all server variables and their default values.

You will most likely also find sample my.cnf files called my-huge.cnf.shmy-large.cnf.sh,my-medium.cnf.sh, and my-small.cnf.sh. You can choose one of these appropriate for your type of installation, and copy and rename it as your my.cnf

 

 

mysqld configuration files and groups

via: https://mariadb.com/kb/en/mysqld-configuration-files-and-groups/

 

Default options are generally read from the following files in the given order:

/etc/my.cnf/etc/mysql/my.cnfmy.cnf

  1.  in the 

DEFAULT_SYSCONFDIRmy.cnf

  1.  in the path, specified in the environment variable 

MYSQL_HOME

  1. the file specified in 

--defaults-extra-fileuser-home-dir/.my.cnf

For an exact list for your system execute mysqld --help --verbose. The full file list will be near the beginning of the output.

This page lists the different mysqld startup options you can use.

mysqld reads the following my.cnf sections:

  1. [mysqld]
  2. [server]
  3. [mysqld-X.X]
  4. [mariadb]
  5. [mariadb-X.X]
  6. [client-server] -- (MariaDB 5.3 and higher)

X.X in the examples above refer to the base (major.minor) version of the server. For example in MariaDB 5.5.32 the base version is 5.5.

For a full list of mysqld options and their current values (based on your local my.cnf), do:


mysqld --print-defaults mysqld --help --verbose



Global Options

The following options determine how mysqld handles option files. They may be given as the first argument:



Option Description

--print-defaults

Print the program argument list and exit.

--no-defaults

Don't read default options from any option file.

--defaults-file=#

Only read default options from the given file #.

--defaults-extra-file=#

Read this file after the global files are read.



MariaDB Options

The full sets of options are described here.

Minimal my.cnf file

Here is a minimal my.cnf file you can install in ~/.my.cnf to test MariaDB 5.3. (For 5.2, you need to copy the section [client-server] to [client] and [mysqld]).



[client-server] # Uncomment these if you want to use a nonstandard connection to MariaDB #socket=/tmp/mysql.sock #port=3306 # This will be passed to all MariaDB clients [client] #password=my_password # The MariaDB server [mysqld] # Directory where you want to put your data data=/usr/local/mysql/var # Directory for the errmsg.sys file in the language you want to use language=/usr/local/mysql/share/mysql/english # Create a file where the InnoDB/XtraDB engine stores it's data loose-innodb_data_file_path = ibdata1:1000M loose-innodb_file_per_table # This is the prefix name to be used for all log, error and replication files log-basename=mysqld # Enable logging by default to help find problems general-log log-slow-queries



The following my.cnf example files are included with MariaDB. Examine them to see more complete examples of some of the many ways to configure MariaDB.

  • my-small.cnf
  • my-medium.cnf
  • my-large.cnf
  • my-huge.cnf

The above example files can usually be found in one of the following directories:

source-file-path/support-files


mysql-install-path/share/mysql

  •  (e.g. 

/usr/local/mysql/share/mysql

  • )

 

 

 

Logging In

via: https://mariadb.com/kb/en/a-mariadb-primer-02-logging-in/

 

Login to the server that has access to the MariaDB database you want to use. Often this is the same machine that is hosting the database, sometimes it isn't.

To connect to the database type:



mysql -u username -p -h host databasename



ps:if this is the same machine that is hosting the database and you don't wanna identify which database you will user,you can type mysql -u username -p;

     if you have a user named 'mysql' with no password,you can type mysql -u mysql.

Replace username with your database username, host with the URI of the database server (if the database is on the local host you can enter 'localhost'), and databasename with the name of the database you want to access. When prompted to enter your password, enter it.

If the copy of MariaDB that you want to access is on the same machine as you, you can ignore the "-h host" argument. The mysql program will assume that you are logging in to a local database.

If your mysql username is the same as your computer login name, you can leave the "-u username" argument off.

If your login is successful you should see something that looks similar to this:

daniel@mycomputer:~$ mysql -u daniel -p -h localhost test
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.2.0-MariaDB-beta Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [test]>

The 'MariaDB [test]>' prompt is what we are interested in. The is where you will enter in all of your SQL statements. More about those on the next page in the primer. For now, let me explain the parts of the prompt:

  1. The "MariaDB" part tells you that you are connected to a MariaDB database.
  2. The word between the brackets ('[' and ']') is the name of the database you are connected to. In the example above we are connected to the 'test' database.
  3. The '>' is the final bit of the prompt. It exists to tell you that the program is ready and waiting for you to enter in your commands.

标签:logging,configuring,installing,server,cnf,file,mysql,MariaDB,my
From: https://blog.51cto.com/u_16070335/6515660

相关文章

  • 解决 This is probably not a problem with npm. There is likely additional logging
    在执行npmrunserve运行项目的时候报错:dengzemiaodeMacBook-Pro:lianshan_vuedengzemiao$npmrunserve......npmERR!codeELIFECYCLEnpmERR!errno1npmERR!lianshan@2.0.0serve:`vue-cli-serviceserve`npmERR!Exitstatus1npmERR!npmERR!Failedatthelia......
  • python 之logging 模块
    一、日志的简单使用1、什么是日志记录你的代码在执行过程中的一些变化(记录的是一些有意义的变化)2、日志的5个等级importlogginglogging.debug('debugmessage')#10logging.info('infomessage')#20logging.warning('warningmessage')#30logging.error('errorm......
  • 解决在 PyCharm 中,logging 与 print 交错的问题
    项目配置->配置->执行->在输出控制台中模拟终端将它勾上即可推测是由于控制台和运行的输出逻辑不同导致的......
  • Python中的logging模块
    官方文档基本用法下面的代码展示了logging最基本的用法。#-*-coding:utf-8-*-importloggingimportsys#获取logger实例,如果参数为空则返回rootloggerlogger=logging.getLogger("AppName")#指定logger输出格式formatter=logging.Formatter('%(ascti......
  • Python日志模块logging高级用法
    问题描述:为了监视程序运行过程,也为了在程序崩溃后进行事后分析来定位错误的原因和位置,不少程序员会在程序中适当的位置使用print()函数输出一些信息。这种方式虽然方便,但是难以实现输出内容的分级。一般建议使用日志模块logging来完成这一任务。在Python中有5个级别的日志,优先级从......
  • 3_Installing Linux, Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04
      地址:https://www.codewithharry.com/blogpost/lamp-stack-ubuntu-20-04/ InstallingLAMPstackonUbuntu20.04in5MinutesThispostwillexplainhowtoinstallLAMPstackonUbuntu20.04.LAMPstackconsistsofthefollowingcomponents:Linux-AnyLi......
  • logging 模块因权限问题写入日志失败
    哈喽大家好,我是咸鱼今天跟大家分享一个使用Python的logging模块写入日志文件时遇到的权限问题,不知道你们有没有遇到过1.案例现象今天上班的时候手机短信收到了zabbix告警,但是发现了不对劲的地方:微信没有收到告警信息,按理说短信跟微信应该是同时收到告警信息的咸鱼这边的......
  • python内置库--logging
    关于logging利用logging,我们在代码里面输出日志信息,这些日志信息可以包括代码中的数据、日志所在模块/文件/行、记录时间、日志级别等等,这些信息可以判断代码运行状态、查看具体代码信息以帮助我们定位问题。在代码量大、模块多时,建议用logging来替代print,输出信息更加方便阅......
  • 【异常】Failed to bind properties under ‘logging.level‘ to java.util.Map<java.l
    本文目录一、背景描述二、问题原因原因1:缺少层级原因2:标点符号使用错误三、解决方案方案一:针对原因1方案二:针对原因2一、背景描述项目技术:springboot2.1.5.RELEASE+logback1.2.3项目启动报错:org.springframework.boot.context.properties.bind.BindException:Failedtobindp......
  • SpringBoot(11) -- Logging
    SpringBoot默认使用的日志框架是logback,所以引入Web依赖后直接使用Logger.引入SpringBoot的Web依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>demo的目录结构......