Migrating Database Charsets to utf8mb4: A Story from the Trenches

utf8mb4In this blog post, we’ll look at options for migrating database charsets to utf8mb4.

Migrating charsets, in my opinion, is one of the most tedious tasks in a DBA’s life. There are so many things involved that can screw up our data, making it work is always hard. Sometimes what seems like a trivial task can become a nightmare very easily, and keeps us working for longer than expected.

I’ve recently worked on a case that challenged me with lots of tests due to some existing schema designs that made InnoDB suffer. I’ve decided to write this post to put together some definitive guide to enact charset conversion with minimal downtime and pain.

  • First disclosure: I can’t emphasize enough that you need to always backup your data. If something goes wrong, you can always roll things back by keeping a healthy set of backups.
  • Second disclosure: A backup can’t be considered a good backup until you test it, so I can’t emphasize enough that running regular backups and also performing regular restore tests is a must-to-do task for being in the safe side.
  • Third and last disclosure: I’m not pretending to present the best or only way to do this exercise. This is the way I consider easiest and painless to perform a charset conversion with minimal downtime.

My approach involves at least one slave for failover and logical/physical backup operations to make sure that data is loaded properly using the right charset.

In this case, we are moving from latin1 (default until MySQL 8.0.0) to utf8mb4 (new default from 8.0.1). In this post, Lefred refers to this change and some safety checks for upgrading. For our change, an important thing to consider: Latin1 charset stores one byte per character, while utf8mb4 can store up to four bytes per character. This change definitely impacts the disk usage, but also makes us hit some limits that I describe later in the plan.

So let’s put out hands in action. First, let’s create a slave using a fresh (non-locking) backup. Remember that these operations are designed to minimize downtime and reduce any potential impact on our production server.

If you already have a slave that can act as a master replacement then you can skip this section. In our source server, configure binlog_format and flush logs to start with fresh binary logs:

Start a streaming backup using Percona Xtrabackup through netcat in the destination server:

and in our source server:

Once the backup is done, untar and restore the backup. Then set up the slave:

Now that we have the slave ready, we prepare our dataset by running two mysqldump processes so we have data and schemas in separate files. You can also run this operation using MyDumper or mysqlpump, but I will keep it easy:

Write down this output, as it may be needed later:

Notice that I’m passing a command as an argument to –databases to dump all databases but mysql, performance_schema and information_schema (hack stolen from this post, with credit to Ronald Bradford).  It is very important to keep the replication stopped, as we will resume replication after fully converting our charset.

Now we have to convert our data to utf8mb4. This is easy as we just need to touch the schema.sql file by running few commands:

Can this be a one-liner? Yes, but I’m not a good basher. 🙂

Now we are ready to restore our data using new encoding:

Notice I’ve enabled the variable innodb_large_prefix. This is important because InnoDB limits index prefixes to 768 bytes by default. If you have an index based in a varchar(255) data type, you will get an error because the new charset exceeds this limit (up to four bytes per character goes beyond 1000 bytes) unless you limit the index prefix. To avoid issues during data load, we enable this variable to extend the limit to 3072 bytes.

Finally, let’s configure our server and restart it to make sure to set new defaults properly. In the my.cnf file, add:

Let’s resume replication after the restart, and make sure everything is ok:

Ok, at this point we should be fine and our data should be already converted to utf8mb4. So far so good. The next step is to failover applications to use the new server, and rebuild the old server using a fresh backup using xtrabackup as described above.

There are few things we need to consider now before converting this slave into master:

  1. Make sure you properly configured applications. Charset and collation values can be set as session level, so if you set your connection driver to another charset then you may end up mixing things in your data.
  2. Make sure the new slave is powerful enough to handle traffic from the master.
  3. Test everything before failing over production applications. Going from Latin1 to utf8mb4 should be straightforward, as utf8mb4 includes all the characters in Latin1. But let’s face it, things can go wrong and we are trying to avoid surprises.
  4. Last but not least, all procedures were done in a relatively small/medium sized dataset (around 600G). But this conversion (done via logical backups) is more difficult when talking about big databases (i.e., in the order of TBs). In these cases, the procedure helps but might not be good enough due to time restrictions (imagine loading a 1TB table from a logical dump — it take ages). If you happen to face such a conversion, here is a short, high-level plan:
    • Convert only smaller tables in the slave (i.e., those smaller than 500MB) following same procedure. Make sure to exclude big tables from the dump using the –ignore-tables parameter in mysqldump.
    • Convert bigger tables via alter table, as follows:
    • Once everything is finished, you can resume replication. Notice you can do dump/conversion/restore in parallel with the altering of bigger tables, which should reduce the time required for conversion.

It’s important to understand why we need the double conversion from latin1 to varbinary to utf8mb4. This post from Marco Tusa largely explains this.

Conclusion

I wrote this guide from my experience working with these type of projects. If you Google a bit, you’ll find a lot of resources that make this work, along with different solutions. What I’ve tried to present here is a guide to help you deal with these projects. Normally, we have to perform these changes in existing datasets that sometimes are big enough to prevent any work getting done via ALTER TABLE commands. Hopefully, you find this useful!

Francisco Bordenave

Francisco has been working in MySQL since 2006, he has worked for several companies which includes Health Care industry to Gaming. Over the last 6 years he has been working as a Remote DBA and Database Consultant which help him to acquire a lot of technical and multi-cultural skills.
He lives in La Plata, Argentina and during his free time he likes to play football, spent time with family and friends and cook.

via Planet MySQL
Migrating Database Charsets to utf8mb4: A Story from the Trenches

Starting MongoDB Database Software

MongoDB Database Software

In this blog post, we will cover how to start MongoDB database software in the three most used platforms: Windows/Linux/MacOS.

If you have just started with NoSQL databases, you might wonder how to evaluate if MongoDB is a good fit for your application.

Percona provides a signed version of MongoDB called Percona Server for MongoDB with a couple of enterprise-grade features included free of charge that runs on all Linux flavors. We also support MongoDB, please check out our support page. But, what if you’re running a test on your study laptop, PC or not. How do you easily start a mongod process for testing? Below I demonstrate how to start MongoDB database software on the three most popular operating systems.

Microsoft Windows

First of all, be aware of this hotfix: https://support.microsoft.com/en-ca/help/2731284/33-dos-error-code-when-memory-memory-mapped-files-are-cleaned-by-using.

You might need to restart the computer after applying the fix. Then download the .zip file. The website only offers an MSI, but we don’t want to install the binaries, we just want to run it.

Click here to download the 3.4.10 version:
http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.4.10.zip

After the download, use your favorite decompressing tool to extract the MongoDB executables. Then cut the extracted folder to your Documents or C: or even a memory stick (but don’t expect high performance):

 

Inside of the bin folder, create a data folder. We are going to use this folder to save our databases.

 

Now we have everything we need to start the database. Open the CMD, and run the following commands to start the database:

C:mongodbbinmongod --dbpath C:mongodbbindata

You will see an output like:

This means the process is running.

In a different CMD, connect to the database using:

C:mongodbbinmongo.exe

I’ve passed the –quiet to omit the warnings:

And here we go, MongoDB is running on a windows machine!

MacOS and Linux configuration:

For macOS, the process is very similar to Windows. The difference is that we can take advantage of the extensive bash commands that the UNIX-like system offers.

Open the terminal. Go to our home/Downloads folder:

cd ~/Downloads

Download MongoDB for MacOS or Linux:

wget https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz
Download mongodb for Linux:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz
untar the file:
tar -xvzf mongodb-osx-ssl-x86_64-3.6.3.tgz
Change the folder name to mongodb // just to make it easier
mv mongodb-osx-x86_64-3.6.3/ ~/Downloads/mongodb
Right now all the binaries are on ~/Downloads/mongodb/
Create a folder to save the database is in ~/Downloads/mongodb/bin/
mkdir ~/Downloads/mongodb/bin/data
Start the mongod process
./mongod --dbpath data

The output must be similar to:

On a different tab run:

~/Downloads/mongodb/bin/mongo

At this point, you should be able to use MongoDB with the default options on MacOS or Linux.

Note that we aren’t enabling authentication either configuring a replica set.

If we don’t pass the –quiet parameter we will receive a few warnings like:

2018-03-16T14:26:20.868-0300 I CONTROL  [initandlisten]
I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
I CONTROL  [initandlisten] **  Read and write access to data and configuration is unrestricted.
I CONTROL  [initandlisten]
I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
I CONTROL  [initandlisten] **       Start the server with --bind_ip <address> to specify which IP
I CONTROL  [initandlisten] **  addresses it should serve responses from, or with --bind_ip_all to
I CONTROL  [initandlisten] **   bind to all interfaces. If this behavior is desired, start the
I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
I CONTROL  [initandlisten]

For more information about how to configure those parameters, please refer to the following blog post and or documentation:

https://www.percona.com/blog/2017/12/15/mongodb-3-6-security-improvements/

https://www.percona.com/blog/2017/05/17/mongodb-authentication-and-roles-creating-your-first-personalized-role/

https://www.percona.com/blog/2016/08/12/tuning-linux-for-mongodb/

To stop the mongod process, use ctrl+c (on any operating system) in the server window.

The post Starting MongoDB Database Software appeared first on Percona Database Performance Blog.

via MySQL Performance Blog
Starting MongoDB Database Software

GunVideo.com – New Video Sharing Website by Lenny Magill

GunVideo.com - New Video Hosting Website by Lenny Magill (2)Lenny Magill, the owner and CEO of GlockStore.com, has recently published a video announcement addressing the new YouTube strict policies regarding firearm-related content. He has created a new website (GunVideo.com) to have a safe platform for hosting their videos and which may also become a video sharing platform for other content creators in the industry. Glock […]

Read More …

The post GunVideo.com – New Video Sharing Website by Lenny Magill appeared first on The Firearm Blog.


via The Firearm Blog
GunVideo.com – New Video Sharing Website by Lenny Magill

Musk’s Flamethrower Looks Like a Toddler’s Toy Next to This Jet-Powered Fire Tornado Cannon

GIF

If you weren’t able to scrape together $500 to buy Elon Musk’s fund-raising flamethrower, YouTube’s Jairus of All has a cheaper, DIY alternative that instead spews a massive spinning tornado of fire using a pair of ducted fans and a tank of liquid propane worn as a backpack.

Jairus’ cannon has a wonderful ‘banned science fair experiment’ aesthetic to it, but it also looks like something Wile E. Coyote would have ordered from the ACME catalog in another ill-conceived attempt to take out the Road Runner. Although, in the wrong hands, Jarius’ creation looks like it could easily take out a small bird, or a nearby planet.

[YouTube via The Awesomer]

via Gizmodo
Musk’s Flamethrower Looks Like a Toddler’s Toy Next to This Jet-Powered Fire Tornado Cannon

No Amount Of Spin Will Make This Gun Control Movement Different

The anti-gunners want to believe this time will be different. In truth, they might be right. Politicians are notoriously wishy-washy when it comes to polling numbers, and many polls seem to be showing broad support for gun control measures, at least in part. It’s not hard to imagine that gun rights are in real jeopardy this time.

However, let’s also be realistic. This particular gun control movement isn’t any different, despite what some people may try and claim (via The Christian Century).

 

When Sam Zeif met with President Trump after the mass shooting at his high school in Parkland, Florida, he broke down in frustration and tears. “How have we not stopped this?” he asked. “After Columbine? After Sandy Hook?”

Zeif’s outrage is understandable. It’s also easy to understand those who have become cynical about political leaders’ persistent unwillingness to tackle gun violence. More than 200 school shootings have taken place since the murders at Columbine, Colorado, in 1999. About 39,000 gun deaths happen each year in the United States. Legislators have mourned but done nothing to address the problem. No meaningful gun control legislation has been passed at the federal level since 1994, when a ban on certain semiautomatic weapons was tucked into the crime bill. That ban expired in 2004.

A couple of points.

First, of those 39,000 deaths, two-thirds are suicides. That tends to be left out when that number is mentioned, and it’s important. Most people understand that you won’t stop suicides by banning the tools people use to commit suicide. If you do that, you’ll eventually have to ban gravity as well. Most of that number is the result of people making a decision and acting on that decision, often without hurting anyone else. Let’s keep that in mind.

Second, since they brought up the assault weapon ban from 1994, it should also be noted that crime was trending downward before the law was passed and continued downward since the law sunset. In other words, the law had no appreciable impact on crime. Imagine that.

Additionally, a red wave overtook Congress following that bill’s passage, which made even Democrats wary of passing gun control legislation.

But the hundreds of thousands of people who gathered at March for Our Lives rallies in late March offered hope that a new movement is under way, led by teens who have seen the trauma of gun violence firsthand and say: no more. What’s hopeful about the latest movement, besides the refreshing leadership of uncynical students, is how it has avoided some of the patterns that have paralyzed previous efforts.

If by “refreshing leadership of uncynical students,” you mean leadership funded by astroturf movements and consisting of foul-mouthed and uninformed individuals, then sure. It’s refreshing.

To start with, the student-led movement has recognized that gun violence affects everyone; it is an issue for people of all races and places. It is an issue that should unite Americans, not divide them.

In her speech at the rally in Washington, 17-year-old Jaclyn Corin acknowledged the racial divide that has to be overcome on this issue. In 2012, black teenagers occupied Florida’s state capitol to protest the shooting of black teenager Trayvon Martin—without getting the kind of attention the Parkland survivors are getting. “But we share this stage today and forever with those communities who have always stared down the barrel of a gun,” said Corin. Edna Chavez, a student from South Los Angeles, was one of the speakers at the Washington rally. “I learned to duck from bullets before I learned to read,” she said.

When are these people going to stop pretending that gun violence is somehow worse than any other form of violence? If your loved one is killed, it doesn’t matter if it was done with a gun or a knife, they’re just as dead. A gun is a tool, but it’s also a tool that is used to save far more lives than take them.

The real problem is violence, plain and simple. Taking away a tool doesn’t make violence go down. In fact, it increases. Take London, for example. England has strict gun control measures, measures that would never fly in the United States even in this current environment. Now London has a higher murder rate than New York City.

If you’re serious about stopping violence, you need to find out why people are violent in the first place. Refusing to start there just shows us you’re not serious about the issue.

The movement also has avoided partisan politics. “This isn’t about the GOP. This isn’t about the Democrats,” said student Cameron Kasky. “This is about us creating a badge of shame for any politicians who are accepting money from the [National Rifle Association] and using us as collateral.” Judging from past failures at gun control, effective strategies and rhetoric will be issue-oriented, not party-oriented.

Yes, Kasky said that.

But the March for Our Lives also featured a lot of bashing of the Republican Party. Marco Rubio has been a repeated target of David Hogg’s, as well as the target of ire for many of the movement’s followers. A look at the signs at the walkouts and the marches show just how wrong this claim is.

Donald Trump called Hogg, Kasky’s fellow traveler, in hopes of having a thoughtful discussion, and Hogg bragged about hanging up on the man. Here he is, the President of the United States, someone who you have to get on your side if you want national level gun control, and Hogg hangs up on him. Why? Because bashing Trump is cool.

But yeah, totally non-partisan.

Third, the movement has focused on electoral process. It has called on young people to register to vote and to hold candidates accountable. “We are going to take this to every election, to every state and every city,” said Parkland student David Hogg. “When politicians send their thoughts and prayers with no action, we say no more.”

And will they?

See, everyone knows that democracy belongs to those who show up. This isn’t new, and the strategy isn’t new. There’s a reason why so many movements also try to include voter registration drives.

But the March for Our Lives only included a very vocal subsection of American youth. There were many more who never showed up at a march. Still, others are rallying in support of the Second Amendment, because even people who don’t own guns can see that taking away our rights in such a way could have horrible ramifications.

However, let’s not kid ourselves; this movement isn’t any different than the ones in the past. It’s the same movement with many of the same people involved behind the scenes. It has a few new, young faces, but they’re spouting the same old lines. Claims of non-partisanship are lies designed to mislead people who won’t look for themselves, hoping the animosities of the past aren’t noticed this time around.

But all this is, in reality, the same old gun control movement dressed up in a shiny new outfit. It’s the same tactics, the same bogus statistics, and the same rhetoric.

Anyone who claims otherwise is either delusional or a liar.

The post No Amount Of Spin Will Make This Gun Control Movement Different appeared first on Bearing Arms.

via Bearing Arms
No Amount Of Spin Will Make This Gun Control Movement Different

Chadwick Boseman Reprised His Role as T’Challa on Last Night’s Saturday Night Live

Chadwick Boseman bringing the King to SNL.

Last night, Chadwick Boseman took a well-deserved victory lap hosting Saturday Night Live, and in the process he naturally returned to the role that’s defined 2018: the Black Panther.

In a compelling rendition of SNL’s recurring Black Jeopardy sketch, T’Challa takes his place in the competition alongside Leslie Jones and Chris Redd’s African American competitors, where he delights and disappoints host Darnell Hayes (Kenan Thompson, the most dedicated sketch actor in history) by showcasing the gulf of experience between his privileged, utopian Wakandan life and the norms of the United States.

Advertisement

Boseman does great here as the delightful fish-out-of-water king, and he eventually gets the hang of it for the funny climax of the sketch. He is a wise king, after all. All hail.

via Gizmodo
Chadwick Boseman Reprised His Role as T’Challa on Last Night’s Saturday Night Live

Composite Metal Foam (CMF) Armor Withstands 23mm HEI Shells

Composite Metal Foam (CMF) Armor Tested Against 23mm HEI Shells1About a year ago, Professor Afsaneh Rabiei of North Carolina State University developed composite metal foam (CMF) armor plates. In a test conducted in 2017, the 1″ thick plate performed impressively against small arms bullets and managed to get NIJ Level IV certification. You can find below the video footage of that test. Recently, the NC State University has […]

Read More …

The post Composite Metal Foam (CMF) Armor Withstands 23mm HEI Shells appeared first on The Firearm Blog.


via The Firearm Blog
Composite Metal Foam (CMF) Armor Withstands 23mm HEI Shells

Hot-air dryers suck in nasty bathroom bacteria and shoot them at your hands

Researchers found these spewing bacteria and spores.

Washing your grubby mitts is one of the all-time best ways to cut your chances of getting sick and spreading harmful germs to others. But using the hot-air dryers common in bathrooms can undo that handy hygienic work.

Hot-air dryers suck in bacteria and hardy bacterial spores loitering in the bathroom—perhaps launched into the air by whooshing toilet flushes—and fire them directly at your freshly cleaned hands, according to a study published in the April issue of Applied and Environmental Microbiology. The authors of the study, led by researchers at the University of Connecticut, found that adding HEPA filters to the dryers can reduce germ-spewing four-fold. However, the data hints that places like infectious disease research facilities and healthcare settings may just want to ditch the dryers and turn to trusty towels.

Indeed, in the wake of the blustery study—which took place in research facility bathrooms around UConn—”paper towel dispensers have recently been added to all 36 bathrooms in basic science research areas in the UConn School of Medicine surveyed in the current study,” the authors note.

via Ars Technica
Hot-air dryers suck in nasty bathroom bacteria and shoot them at your hands

Star Wars: The Last Laser Master

The Auralnauts have finished up their epic comedic retelling of the first six episodes of Star Wars with episode 6, The Last Laser Master. Follow Laser Master Duke Dirtfarmer and his friends in the fight against the Empire and its fearsome planet-killing weapon: Laser Moon II.

You can watch the five other episodes — including Jedi Party, The Friend Zone, and Revenge of Middle Management — in this playlist.

For snackier Auralnauts fare, see How to make a blockbuster movie trailer, some Bane outtakes from the Dark Knight Rises, and the Star Wars throne room scene minus the John Williams score.

Tags: movies   remix   Star Wars   video
via kottke.org
Star Wars: The Last Laser Master

The Chmod Command and Linux File Permissions Explained

So you’ve sliced your way through all the common misconceptions about Linux, found a flavor of Linux that you like, but now you’re confused because you haven’t the faintest clue about terminal commands and Linux file permissions?

Or maybe you have a website that’s hosted on a Linux server and you’ve run into some file permission issues that can only be solved with some command line magic.

Regardless, one of the most essential Linux commands to learn


An A-Z of Linux – 40 Essential Commands You Should Know




An A-Z of Linux – 40 Essential Commands You Should Know

Linux is the oft-ignored third wheel to Windows and Mac. Yes, over the past decade, the open source operating system has gained a lot of traction, but it’s still a far cry from being considered…
Read More

is a small but powerful command called chmod. But before we explain what the command does, we have to first understand a little bit about how Linux handles file security.

The Basics of Linux File Permissions

Linux operating systems are actually Unix-like systems (understanding Linux vs. Unix), and Unix-like systems approach file permissions like so:

Every file has an owner, which determines the file’s “user class.” Every file also has a group, which determines the file’s “group class.” Any system user who isn’t the owner and doesn’t belong in the same group is determined to be others.

All files on Unix-like systems have permissions assigned to all three classes, and these determine which actions can be taken by said classes for the given file.

The three actions available on a Unix-like system are: read (the ability to open and view the contents of the file), write (the ability to open and modify the contents of a file), and execute (the ability to run the file as an executable program).

In other words, a file’s permissions determine whether or not:

  • The owner can read, write, and execute the file.
  • The group can read, write, and execute the file.
  • Anyone else can read, write, and execute the file.

Linux file permissions can be displayed in two formats.

The first format is called symbolic notation, which is a string of 10 characters: one character that represents the file type, then nine characters that represent the file’s read (r), write (w), and execute (x) permissions in order of owner, group, and others. If not permitted, the dash symbol (-) is used.

For example:

-rwxr-xr--

This means it’s a regular file with read, write, and execute permissions for the owner; read and execute permissions for the group; and only read permissions for everyone else.

The second format is called numeric notation, which is a string of three digits that each represent user, group, and other permissions, respectively. Each digit can range from 0 to 7, and each digit’s value is obtained by summing the class’s permissions:

  • 0 means no permissions allowed.
  • +1 if the class can execute the file.
  • +2 if the class can write to the file.
  • +4 if the class can read the file.

In other words, the meaning of each digit value ends up being:

  • 0: No permission
  • 1: Execute
  • 2: Write
  • 3: Write and execute
  • 4: Read
  • 5: Read and execute
  • 6: Read and write
  • 7: Read, write, and execute

So the above example (-rwxr-xr--) would be 754 in numeric notation.

That’s Linux file permissions in a nutshell.

What Is Chmod?

On Unix-like systems, chmod is a system-level command that stands for “change mode” and allows you to manually change the permission settings of a file.

Not to be confused with chown, which is another system-level command on Unix-like systems that stands for “change owner” and lets you assign ownership of a file to another user, or chgrp, which stands for “change group” and assigns a file to a different group. These are important to know, but not as commonly used as chmod.

What Does Chmod 644 Mean?

Setting a file’s permissions to 644 makes it so only the owner can access and modify the file however they want while everyone else can only access without modifying, and nobody can execute the file—not even the owner. This is the ideal setting for files that are publicly accessible because it balances flexibility with security.

What Does Chmod 755 Mean?

Setting a file’s permissions to 755 is basically the same thing as 644 except everyone also has execute permissions. This is mainly used for publicly accessible directories because the execute permission is needed in order to change into a directory.

What Does Chmod 555 Mean?

Setting a file’s permissions to 555 makes it so that the file cannot be modified at all by anyone except the system’s superuser (learn more about the Linux superuser


What Is SU & Why Is It Important to Using Linux Effectively?




What Is SU & Why Is It Important to Using Linux Effectively?

The Linux SU or root user account is a powerful tool that can be helpful when used correctly or devastating if used recklessly. Let’s look at why you should be responsible when using SU.
Read More

). This isn’t as commonly used as 644, but it’s still important to know because the read-only setting prevents accidental changes and/or tampering.

What Does Chmod 777 Mean?

Setting a file’s permissions to 777 makes it so anyone can do anything they want with the file. This is a huge security risk, especially on web servers! Literally anyone can access the file, modify it however they want, and execute it on the system. You can imagine the potential damage if a rogue user got their hands on it.

How to Use Chmod on Linux

The chmod command has a simple format:

chmod [permissions] [file]

Permissions can be given in numeric notation, which is the best format to use when you want to assign specific permissions for all classes:

chmod 644 example.txt

Permissions can also be given in symbolic notation, which is useful when you only want to modify the permissions of a particular class. For example:

chmod u=rwx example.txt
chmod g=rw example.txt
chmod o=rw example.txt

You can modify permissions for multiple classes, such as this example which sets the owner to read/write/execute but the group and others to read/execute:

chmod u=rwx,g=rw,o=rw example.txt

When assigning the same permissions to multiple classes, you can combine them:

chmod u=rwx,go=rw example.txt

But the beauty of using symbolic notation shines when you only want to add or remove the permission for a particular action for a particular class.

For example, this adds the execute permission for the file’s owner:

chmod u+x example.txt

And this removes the write and execute permissions for other users:

chmod o-wx example.txt

Lastly, if you want to apply a particular set of permissions to all files and folders within a particular directory (i.e. a recursive chmod), use the -R option and target a directory:

chmod -R 755 example_directory

While the chmod command looks a bit crazy at first glance, it’s actually quite simple and entirely logical. If you understand the above, you’ve basically mastered chmod!

Learn More About Mastering Linux

Commands like chmod, chown, and chgrp are just the tip of the Linux iceberg. If you’re brand new to the operating system, we recommend checking out these neat tricks for Linux newbies as well as these Linux commands you should never run.

But most importantly, you’d do best by checking out our comprehensive beginner’s guide to Ubuntu and Linux


Ubuntu: A Beginner’s Guide




Ubuntu: A Beginner’s Guide

Curious about Ubuntu, but not sure where to start? Everything you could possibly need to get started with the latest version of Ubuntu is right here, written in easy-to-understand, plain English.
Read More

, which will teach you everything you need to know to get started and familiarized enough to feel comfortable.



via MakeUseOf.com
The Chmod Command and Linux File Permissions Explained